-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
60 lines (41 loc) · 1.7 KB
/
server.js
File metadata and controls
60 lines (41 loc) · 1.7 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
52
53
54
55
56
57
58
59
60
/**
* Created by zhoulongfei on 2018/6/13.
* E-mail:36995800@163.com
*/
let http = require('http');
let path=require('path');
let express = require('express');
let bodyParser = require('body-parser');
//let multer = require('multer');
let app = express();
app.use(require('morgan')('short'));
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({extended: true})); // for parsing application/x-www-form-urlencoded
//app.use(multer()); // for parsing multipart/form-data
// ************************************
// This is the real meat of the example
// ************************************
// Step 1: Create & configure a webpack compiler
let webpack = require('webpack');
let webpackConfig = require(process.env.WEBPACK_CONFIG ? process.env.WEBPACK_CONFIG : './webpack.config');
let compiler = webpack(webpackConfig);
// Step 2: Attach the dev middleware to the compiler & the server
app.use(require("webpack-dev-middleware")(compiler, {
noInfo: true, publicPath: webpackConfig.output.publicPath
}));
// Step 3: Attach the hot middleware to the compiler & the server
app.use(require("webpack-hot-middleware")(compiler, {
log: console.log, path: '/__webpack_hmr', heartbeat: 10 * 1000, reload: true
}));
app.use('/static',express.static(path.resolve(__dirname,'./dist/')));
// Do anything you like with the rest of your express application.
app.get("/", function (req, res) {
res.sendFile(__dirname + '/index.html');
});
/*------------------测试接口------------------*/
if (require.main === module) {
let server = http.createServer(app);
server.listen(process.env.PORT || 3030, function () {
console.log("Listening on %j", server.address());
});
}