@@ -10,7 +10,7 @@ import compose from 'koa-compose'// middleware composer
10
10
import compress from 'koa-compress' // HTTP compression
11
11
import session from 'koa-session' // session for flash messages
12
12
import api from './api'
13
- import constants from './utils/constants '
13
+ import consts from './utils/consts '
14
14
import config from '../nuxt.config.js'
15
15
import debugModule from 'debug' // small debugging utility
16
16
@@ -19,8 +19,8 @@ import proxy from 'koa-proxies'
19
19
// Start nuxt.js
20
20
async function start ( ) {
21
21
const isWin = / ^ w i n / . test ( process . platform )
22
- const host = constants . HOST
23
- const port = constants . PORT
22
+ const host = consts . HOST
23
+ const port = consts . PORT
24
24
const debug = debugModule ( 'app' )
25
25
const app = new Koa ( )
26
26
@@ -65,8 +65,11 @@ async function start () {
65
65
await next ( )
66
66
} )
67
67
68
+ const SESSION_CONFIG = {
69
+ key : consts . SESS_KEY
70
+ }
68
71
// session for flash messages (uses signed session cookies, with no server storage)
69
- app . use ( session ( app ) ) // note [email protected] is v1 middleware which generates deprecation notice
72
+ app . use ( session ( SESSION_CONFIG , app ) ) // note [email protected] is v1 middleware which generates deprecation notice
70
73
71
74
const nuxt = new Nuxt ( config )
72
75
// Build only in dev mode
@@ -83,7 +86,7 @@ async function start () {
83
86
84
87
app . use ( async ( ctx , next ) => {
85
88
await next ( )
86
- if ( ctx . state . subapp !== constants . API ) {
89
+ if ( ctx . state . subapp !== consts . API ) {
87
90
ctx . status = 200 // koa defaults to 404 when it sees that status is unset
88
91
ctx . req . session = ctx . session
89
92
await nuxt . render ( ctx . req , ctx . res )
@@ -118,7 +121,7 @@ async function start () {
118
121
// note no 'next' after composed subapp, this must be the last middleware
119
122
app . use ( async function composeSubapp ( ctx , next ) {
120
123
switch ( ctx . state . subapp ) {
121
- case constants . API : await compose ( api . middleware ) ( ctx ) ; break
124
+ case consts . API : await compose ( api . middleware ) ( ctx ) ; break
122
125
}
123
126
} )
124
127
0 commit comments