-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
40 lines (33 loc) · 903 Bytes
/
server.js
File metadata and controls
40 lines (33 loc) · 903 Bytes
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
import path from 'path'
import express from 'express'
import expressGraphQL from 'express-graphql'
import webpack from 'webpack'
import webpackMiddleware from 'webpack-dev-middleware'
import webpackHotMiddleware from 'webpack-hot-middleware'
import config from './webpack.config.js'
import {db} from './db'
import {schema} from './src/graphql/schema'
const port = process.env.PORT || 8080
const app = express()
app.use(express.static(__dirname + '/dist'))
const compiler = webpack(config)
const middleware = webpackMiddleware(compiler, {
publicPath: config.output.publicPath,
})
app.use(
'/graphql',
expressGraphQL({
schema: schema,
graphiql: true,
context: {
db: db,
},
})
)
app.use(middleware)
app.use(webpackHotMiddleware(compiler))
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'))
})
app.listen(port)
console.log(`server started at port ${port}`)