forked from 17Q4MX2hmktmpuUKHFuoRmS5MfB5XPbhod/dropzone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
69 lines (58 loc) · 1.83 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
68
69
import express from 'express';
const app = express();
const staticResources = ['app.js', 'style.css', 'css/bootstrap.css', 'css/animate.css',
'bootstrap-theme.min.css', 'js/bootstrap.min.js', 'css/bootstrap-darkly.css',
'img/dropzone-logo-32x32.png', 'js/dropzone-lib.min.js',
'fonts/glyphicons-halflings-regular.svg',
'fonts/glyphicons-halflings-regular.ttf',
'fonts/glyphicons-halflings-regular.eot',
'fonts/glyphicons-halflings-regular.woof',
'fonts/glyphicons-halflings-regular.woof2'
]
staticResources.forEach( (resource) => {
app.get(`/${resource}`, (req, res) => {
if (process.env.PRODUCTION) {
res.sendFile(`${__dirname}/build/${resource}`);
} else {
res.redirect(`//localhost:9090/build/${resource}`);
}
});
});
// Serve index page
app.get('*', (req, res) => {
res.sendFile(__dirname + '/build/index.html');
});
/*************************************************************
*
* Webpack Dev Server
*
* See: http://webpack.github.io/docs/webpack-dev-server.html
*
*************************************************************/
if (!process.env.PRODUCTION) {
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.local.config');
new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
noInfo: true,
headers: { "Access-Control-Allow-Origin": "*" },
historyApiFallback: true
}).listen(9090, 'localhost', (err, result) => {
if (err) {
console.log(err);
}
});
}
/******************
*
* Express server
*
*****************/
const port = process.env.PORT || 8080;
const server = app.listen(port, () => {
const host = server.address().address;
const port = server.address().port;
console.log('Drop Zone listening at http://%s:%s', host, port);
});