This repository has been archived by the owner on Mar 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
67 lines (51 loc) · 1.95 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* globals process, __dirname */
/*
|--------------------------------------------------------------------------
| Server.js
|--------------------------------------------------------------------------
|
| This is your local server. Kickstart it by running npm server and it will serve your plugin so that you can install it
| on dev.dashboard.infomaker.io.
|
*/
'use strict'
const express = require('express')
const app = express()
const cors = require('cors')
const http = require('http').Server(app)
const manifest = require('./manifest.json')
const ip = require('ip')
process.env.PORT = process.env.PORT || 7000
const PORT = process.env.PORT
const useHOT = process.env.HOT === "1"
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*")
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, X-Access-Token")
res.header("Access-Control-Allow-Methods", "DELETE, GET, HEAD, POST, PUT, OPTIONS, TRACE")
if (req.url.match(/(manifest.json)$/)) {
res.header("Content-Type", "application/json; charset=utf-8")
}
next()
})
app.use(cors())
if (useHOT) {
const webpack = require('webpack')
const webpackDevMiddleware = require("webpack-dev-middleware")
const webpackHotMiddleware = require("webpack-hot-middleware")
const webpackConfig = require("./__tooling__/webpack/webpack.dev.hot.config.js")
const compiler = webpack(webpackConfig)
app.use(webpackDevMiddleware(compiler, {
hot: true,
historyApiFallback: true,
publicPath: webpackConfig.output.publicPath
}))
app.use(webpackHotMiddleware(compiler, {
path: "/__webpack_hmr",
}))
} else {
app.use(express.static(__dirname + '/build'))
}
http.listen(PORT, () => {
console.log(`\n🎉 ${manifest.name} manifest.json served at http://${ip.address()}:${PORT}/manifest.json`)
console.log(`\n Use this url to install the plugin at http://dev.dashboard.infomaker.io`)
})