-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (36 loc) · 1.24 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
// Read env variables
require('dotenv').config();
// Webpack for compress files > optimization
var webpack = require('webpack')
var webpackDevMiddleware = require('webpack-dev-middleware')
var webpackHotMiddleware = require('webpack-hot-middleware')
var config = require('./webpack.config')
// Express for http request API
var express = require('express')
// Http will use express to create a server
var http = require('http');
// Open url in browser
const opn = require('opn');
// create the app
var app = new (express)()
// Compile client files
var compiler = webpack(config)
app.use(webpackDevMiddleware(compiler, { noInfo: true, publicPath: config.output.publicPath }))
app.use(webpackHotMiddleware(compiler))
// Deliver static folder for static files like pictures
app.use(express.static('webapp/static'));
// All request go to index
app.get("*", function(req, res) {
res.sendFile(__dirname + '/webapp/main/index.html')
})
// Create the HTTP server
var httpServer = http.createServer(app);
var port = process.env.PORT || 8081;
httpServer.listen(port, function(error) {
if (error) {
console.error(error)
} else {
console.info("==> 🌎 [HTTP] Open up http://localhost:"+port+"/ in your browser.");
opn("http://localhost:"+port+"/");
}
});