Add header: Access-Control-Allow-Methods


Add to the before hook of lib/D2/Ajax.pm:


header 'Access-Control-Allow-Methods' => 'GET, POST, OPTIONS, DELETE';

Add to lib/D2/Ajax.pm


options '/api/v2/item/:id' => sub {
    return '';
};

Test it:


snippets/8/t/options.t
my $options  = $test->request( OPTIONS '/api/v2/item/anything' );
ok $options->is_success, '[POST /] successful';
is $options->header('Access-Control-Allow-Methods'), 'GET, POST, OPTIONS, DELETE';