File tree 2 files changed +12
-13
lines changed
2 files changed +12
-13
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import KnexStore from 'koa-generic-session-knex';
8
8
import userAgent from 'koa-useragent' ;
9
9
import etag from 'koa-etag' ;
10
10
import views from 'koa-views' ;
11
+ import cors from '@koa/cors' ;
11
12
12
13
import config from './config' ;
13
14
import errorHandler from './middlewares/errorHandler' ;
@@ -34,6 +35,16 @@ app.keys = [config.cookies.key];
34
35
35
36
app . proxy = config . env === 'production' ;
36
37
38
+ app . use ( cors ( {
39
+ credentials : true ,
40
+ origin ( ctx ) {
41
+ const requestOrigin = ctx . get ( 'Origin' ) ;
42
+ if ( config . cors . origin . indexOf ( requestOrigin ) > - 1 ) {
43
+ return requestOrigin ;
44
+ }
45
+ return false ;
46
+ } ,
47
+ } ) ) ;
37
48
app . use ( bodyParser ( ) ) ;
38
49
app . use ( KoaPinoLogger ( { logger } ) ) ;
39
50
app . use ( errorHandler ( ) ) ;
Original file line number Diff line number Diff line change 1
- import cors from '@koa/cors' ;
2
1
import config from '../config' ;
3
2
4
- const corsMiddleware = cors ( {
5
- credentials : true ,
6
- origin ( ctx ) {
7
- const requestOrigin = ctx . get ( 'Origin' ) ;
8
- if ( config . cors . origin . indexOf ( requestOrigin ) > - 1 ) {
9
- return requestOrigin ;
10
- }
11
- return false ;
12
- } ,
13
- } ) ;
14
-
15
3
export default ( ctx , next ) => {
16
4
if ( config . env === 'test' ) {
17
5
return next ( ) ;
@@ -24,5 +12,5 @@ export default (ctx, next) => {
24
12
return Promise . resolve ( ) ;
25
13
}
26
14
27
- return corsMiddleware ( ctx , next ) ;
15
+ return next ( ) ;
28
16
} ;
You can’t perform that action at this time.
0 commit comments