-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
72 lines (59 loc) · 2.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
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
70
71
72
const auth = require('./server/auth-route');
const search = require('./server/search-route');
const bodyParser = require('body-parser');
const express = require('express');
const path = require('path');
const port = (process.env.PORT || 8080);
const app = express();
const publicPathS = express.static(path.join(__dirname, 'public'), { redirect : false });
app.use(bodyParser.json());
if (process.env.NODE_ENV !== 'production') {
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const DashboardPlugin = require('webpack-dashboard/plugin');
const config = require('./webpack.dev.config.js');
const compiler = webpack(config);
compiler.apply(new DashboardPlugin());
app.use(webpackHotMiddleware(compiler));
app.use(webpackDevMiddleware(compiler, {
noInfo : true,
stats : {
colors : true
},
publicPath : config.output.publicPath
}));
const indexPathD = path.join(__dirname, 'index.html');
const publicPath = express.static(path.join(__dirname, 'public'));
app.use('/public', publicPath);
app.use('/api/login', auth);
app.use('/api/search', search);
app.get('/', function (_, res) { res.sendFile(indexPathD) });
app.get('*', function (_, res) { res.sendFile(indexPathD) });
} else {
//const client = require('redis').createClient();
//const limiter = require('express-limiter')(search, client);
//limiter({
//path: '/api/search',
//method: 'post',
//lookup: 'userName',
//whitelist:function(req) {
//return userName == "Luke Skywalker"
//},
//total: 5,
//expire: 1000 * 4
//});
const indexPath = path.join(__dirname, 'public/index.html');
app.use(publicPathS);
app.use('/api/login', auth);
app.use('/api/search', search);
app.get('/', function (_, res) { res.sendFile(indexPath) });
app.get('*', function (_, res) { res.sendFile(indexPath) });
}
app.listen(port, function(err) {
if (err) {
console.log(err);
return;
}
});
console.log(`Listening at http://localhost:${port}`);