-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_hot.js
81 lines (66 loc) · 1.74 KB
/
server_hot.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
73
74
75
76
77
78
79
80
var webpack = require('webpack');
var express = require('express');
var config = require('./webpack.hot');
var proxyMiddleware = require('http-proxy-middleware');
var bodyParser = require("body-parser");
var app = express();
var compiler = webpack(config);
app.use(bodyParser.urlencoded({ extended: false }));
app.use(require('webpack-dev-middleware')(compiler, {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
inline: true,
progress: true,
stats: {
colors: true,
}
}));
// 代理服务器, 到时候替换成后端接口和地址
app.use('/user', proxyMiddleware({
target: 'http://127.0.0.1:5000',
changeOrigin: true,
}));
app.use('/post', proxyMiddleware({
target: 'http://127.0.0.1:5000',
changeOrigin: true,
}));
app.use('/album', proxyMiddleware({
target: 'http://127.0.0.1:5000',
changeOrigin: true,
}));
//app.use('/static', proxyMiddleware({
// target: 'http://127.0.0.1:5000',
// changeOrigin: true,
//}));
app.use(require('webpack-hot-middleware')(compiler));
//监听请求
app.post('/api/login', function(req, res) {
var username = req.body.username;
var password = req.body.password;
/*
setTimeout(function(){
if (username == 'admin' && password == '123456' ){
res.send({ code: '0', data: userInfo });
}else{
res.send({ code:'999', data: null, msg: '账号或者密码错误' });
}
res.end();
}, 1000);
*/
});
app.post('/api/logout', function(req, res) {
/*
setTimeout(function(){
res.send({ code: '0', data: null });
res.end();
}, 1500)
*/
});
//将其他路由,全部返回index.html
app.get('*', function(req, res) {
res.sendFile(__dirname + '/index.html')
});
app.listen(8084, function() {
console.log('正常打开8084端口')
});