forked from ShieldBattery/ShieldBattery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
electron-dev-server.js
38 lines (32 loc) · 1002 Bytes
/
electron-dev-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
const PORT = 5566
import express from 'express'
import webpack from 'webpack'
import webpackDevMiddleware from 'webpack-dev-middleware'
import webpackHotMiddleware from 'webpack-hot-middleware'
import config from './webpack.config'
const app = express()
const compiler = webpack(config)
const middleware = webpackDevMiddleware(compiler, {
publicPath: config.output.publicPath,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
},
})
app.use(middleware)
app.use(webpackHotMiddleware(compiler, { log: console.log }))
const server = app.listen(PORT, 'localhost', err => {
if (err) {
console.error(err)
return
}
console.log(`Listening at http://localhost:${PORT}`)
})
process.on('SIGTERM', () => {
console.log('Stopping electron dev server')
middleware.close()
server.close(() => {
process.exit(0)
})
})