-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathserver.js
75 lines (60 loc) · 2.03 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
73
74
75
var path = require('path')
var express = require('express')
var proxy = require("express-http-proxy")
var config = require('./config')
var webpack = require('webpack')
var webpackConfig = require('./webpack.config.js')
// default port where dev server listens for incoming traffic
var port = process.env.PORT || config.port
// Define HTTP proxies to your custom API backend
// var hosts = "http://localhost:1983";
var app = express()
var compiler = webpack(webpackConfig)
var devMiddleware = require('webpack-dev-middleware')(compiler, {
publicPath: webpackConfig.output.publicPath,
stats: {
colors: true,
chunks: false
}
})
var hotMiddleware = require('webpack-hot-middleware')(compiler)
// force page reload when html-webpack-plugin template changes
compiler.plugin('compilation', function (compilation) {
compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
hotMiddleware.publish({ action: 'reload' })
cb()
})
})
// serve webpack bundle output
app.use(devMiddleware)
// enable hot-reload and state-preserving
// compilation error display
app.use(hotMiddleware)
app.get("/", function(req, res) {
res.sendFile(__dirname + '/index.html');
});
//待删除
app.get("/passing", function(req, res) {
res.sendFile(__dirname + '/passing.html');
});
app.get("/account", function(req, res) {
res.sendFile(__dirname + '/account.html');
});
//设置 proxy 配置host
// var apiProxy = proxy(hosts, {
// forwardPath:function(req,res){
// return req._parsedUrl.path
// }
// })
// app.get("/*", apiProxy);
// app.post("/*", apiProxy);
//正式环境则不需要,对应文件须修改js库路径
// serve pure static assets
// app.use('/dist', express.static('dist'));
app.use('/public', express.static('assets/public'));
module.exports = app.listen(port, function (err) {
if(err){
return console.log(err)
}
console.log('Listening at http://localhost:' + port + '\n')
})