View | Details | Raw Unified | Return to bug 24369
Collapse All | Expand All

(-)a/Koha/REST/V1.pm (-4 / +13 lines)
Lines 39-48 Overloaded Mojolicious->startup method. It is called at application startup. Link Here
39
sub startup {
39
sub startup {
40
    my $self = shift;
40
    my $self = shift;
41
41
42
    # Remove /api/v1/app.pl/ from the path
42
    $self->hook(
43
    $self->hook( before_dispatch => sub {
43
        before_dispatch => sub {
44
        shift->req->url->base->path('/');
44
            my $c = shift;
45
    });
45
46
            # Remove /api/v1/app.pl/ from the path
47
            $c->req->url->base->path('/');
48
49
            # Handle CORS
50
            $c->res->headers->header( 'Access-Control-Allow-Origin' =>
51
                  C4::Context->preference('AccessControlAllowOrigin') )
52
              if C4::Context->preference('AccessControlAllowOrigin');
53
        }
54
    );
46
55
47
    # Force charset=utf8 in Content-Type header for JSON responses
56
    # Force charset=utf8 in Content-Type header for JSON responses
48
    $self->types->type( json    => 'application/json; charset=utf8' );
57
    $self->types->type( json    => 'application/json; charset=utf8' );
(-)a/t/db_dependent/api/v1/auth.t (-2 / +20 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 1;
20
use Test::More tests => 2;
21
use Test::Mojo;
21
use Test::Mojo;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 107-112 subtest 'under() tests' => sub { Link Here
107
    $schema->storage->txn_rollback;
107
    $schema->storage->txn_rollback;
108
};
108
};
109
109
110
subtest 'CORS support' => sub {
111
112
    plan tests => 6;
113
114
    t::lib::Mocks::mock_preference('AccessControlAllowOrigin','');
115
    $t->get_ok("/api/v1/patrons")
116
      ->header_is( 'Access-control-allow-origin', undef, 'Header not returned' );
117
      # FIXME: newer Test::Mojo has header_exists_not
118
119
    t::lib::Mocks::mock_preference('AccessControlAllowOrigin',undef);
120
    $t->get_ok("/api/v1/patrons")
121
      ->header_is( 'Access-control-allow-origin', undef, 'Header not returned' );
122
    # FIXME: newer Test::Mojo has header_exists_not
123
124
    t::lib::Mocks::mock_preference('AccessControlAllowOrigin','*');
125
    $t->get_ok("/api/v1/patrons")
126
      ->header_is( 'Access-control-allow-origin', '*', 'Header set' );
127
};
128
110
sub create_user_and_session {
129
sub create_user_and_session {
111
    my $user = $builder->build(
130
    my $user = $builder->build(
112
        {
131
        {
113
- 

Return to bug 24369