-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
46 lines (35 loc) · 1.34 KB
/
index.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
require('dotenv').config();
const express = require('express');
// const secure = require('express-force-https');
const expressStaticGzip = require("express-static-gzip");
const webpack = require('webpack');
const webpackConfig = require('./webpack.config.js');
const isProduction = process.env.NODE_ENV === 'production';
const app = express();
console.log(`${isProduction ? 'Production' : 'Dev'} Build!`);
// If in dev, hook up webpack dev middleware for hmr
if (!isProduction) {
const compiler = webpack(webpackConfig);
app.use(require('webpack-hot-middleware')(compiler));
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: webpackConfig.output.publicPath,
}));
}
const http = require('http').Server(app);
const io = require('socket.io')(http);
const socket = require('./lib/socket');
socket.init(io);
const port = process.env.PORT || 4200;
// Try to send down gzipped static assets if available
app.use('/', expressStaticGzip(__dirname + '/public', {}));
// Try to redirect to https
// app.use(secure); TODO fix "Access to Font at 'https://...' from origin 'http://...' has been blocked by CORS policy"
// Reroute unmatched routes to home page
app.use((req, res) => {
res.sendFile(__dirname + '/public/index.html');
});
// Start server
http.listen(port, function () {
console.log('listening on *:' + port);
});