-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
51 lines (42 loc) · 2.31 KB
/
app.js
File metadata and controls
51 lines (42 loc) · 2.31 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
49
50
51
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const apiRoutes = require('./api');
const app = new express();
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Back-end configuration //////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use('/api', apiRoutes);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Front-end configuration /////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Webpack configuration
if (process.env.NODE_ENV === 'development') {
const webpack = require('webpack');
const config = require('./webpack.development.js');
const compiler = webpack(config);
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
app.use(webpackDevMiddleware(compiler, {noInfo: true, publicPath: config.output.publicPath}));
app.use(webpackHotMiddleware(compiler));
}
// Serve public path
app.use(express.static(path.resolve(__dirname, 'public')));
app.get('*', function (req, res) {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Serve, server! //////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const port = process.env.PORT || 1993;
app.listen(port, function (error) {
if (error) {
console.error(error);
} else {
if (process.env.NODE_ENV === 'development') {
console.info("==> Listening on port %s. Open up http://localhost:%s/ in your browser.", port, port)
}
}
});