-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver-dev.js
More file actions
48 lines (40 loc) · 1.03 KB
/
server-dev.js
File metadata and controls
48 lines (40 loc) · 1.03 KB
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
const express = require('express')
const graphqlHTTP = require('express-graphql')
const {db} = require('./src/server/db')
const {schema} = require('./src/graphql/schema')
var webpack = require('webpack')
var webpackConfig = require('./webpack.config')
var compiler = webpack(webpackConfig)
const port = process.env.PORT || 8080
const app = express()
app.use(require('webpack-dev-middleware')(compiler))
app.use(require('webpack-hot-middleware')(compiler))
app.use(express.static('dist'))
app.use(express.static('assets'))
app.use(
'/graphql',
graphqlHTTP({
schema: schema,
graphiql: true,
context: {
db: db,
},
})
)
app.get('*', async (req, res) => {
res.send(`
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1"/>
<script src="bundle.js" defer></script>
</head>
<body>
<div id="root"></div>
</body>
</html>
`)
})
app.listen(port)
// eslint-disable-next-line no-console
console.log(`server started at port ${port}`)