Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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:

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';