-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
40 lines (33 loc) · 1.09 KB
/
server.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
/*
* @Author: terry
* @Date: 2018-07-27 14:13:07
* @Last Modified by: [email protected]
* @Last Modified time: 2018-07-27 14:13:07
*/
import express from 'express'
import { Nuxt, Builder } from 'nuxt'
import bodyParser from 'body-parser';
import globalConfig from './config'
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express';
import schema from './apollo/schema'
const app = express()
const host = globalConfig.host
const port = globalConfig.port
app.set('port', port)
app.use('/graphqli', bodyParser.json(), graphqlExpress({ schema }));
app.use('/graphql', graphiqlExpress({ endpointURL: '/graphqli' }));
// Import and Set Nuxt.js options
let config = require('./nuxt.config.js')
config.dev = !(process.env.NODE_ENV === 'production')
// Init Nuxt.js
const nuxt = new Nuxt(config)
// Build only in dev mode
if (config.dev) {
const builder = new Builder(nuxt)
builder.build()
}
// Give nuxt middleware to express
app.use(nuxt.render)
// 监听指定端口
app.listen(port, host)
console.log('Server listening on ' + host + ':' + port) // eslint-disable-line no-console