forked from ezpaarse-project/analogist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (42 loc) · 1.14 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* eslint no-console: 0 */
const Nuxt = require('nuxt')
const app = require('express')()
const logger = require('morgan')
const config = require('config')
const session = require('express-session')
const MongoStore = require('connect-mongo')(session)
const mongo = require('./lib/mongo')
process.env.PORT = config.port
const isDev = app.get('env') !== 'production'
if (isDev) { app.use(logger('dev')) }
app.use(session({
resave: false,
saveUninitialized: false,
secret: config.cookie.secret,
cookie: { maxAge: config.cookie.maxAge },
unset: 'destroy',
store: new MongoStore({ db: mongo.db })
}))
// Import API Routes
app.use('/api', require('./api'))
// API error handler
app.use((err, req, res, next) => {
res.status(err.status || 500)
res.write(isDev ? err.stack : err.message)
res.end()
})
// Import and Set Nuxt.js options
const nuxtConfig = require('./nuxt.config.js')
nuxtConfig.dev = isDev
// Init Nuxt.js
const nuxt = new Nuxt(nuxtConfig)
app.use(nuxt.render)
// Build only in dev mode
if (nuxtConfig.dev) {
nuxt.build()
.catch((error) => {
console.error(error)
process.exit(1)
})
}
module.exports = app