1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | const path = require('path');
|
7 | const express = require('express');
|
8 | const mockMiddleware = require('@nfe/mock-middleware');
|
9 | const webpack = require('webpack');
|
10 |
|
11 | const config = require('../webpack.config');
|
12 |
|
13 |
|
14 | const app = express();
|
15 | const compiler = webpack(config);
|
16 |
|
17 | app.use(require('webpack-dev-middleware')(compiler, {
|
18 | noInfo: true,
|
19 | publicPath: config.output.publicPath
|
20 | }));
|
21 |
|
22 | app.use(require('webpack-hot-middleware')(compiler, {
|
23 | reload: false
|
24 | }));
|
25 |
|
26 | app.use(express.static('../site'));
|
27 |
|
28 |
|
29 | const isRemote = process.env.SCENE === 'remote';
|
30 |
|
31 | let mapConfig = {
|
32 | map: 'mock/local.js',
|
33 | delay: 300
|
34 | };
|
35 |
|
36 | if (isRemote) {
|
37 | mapConfig = {
|
38 | map: 'mock/remote.js',
|
39 | delay: 0
|
40 | };
|
41 | }
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | app.get('*', function (req, res) {
|
47 |
|
48 | res.send('404!!!');
|
49 | });
|
50 |
|
51 | const port = 9000;
|
52 |
|
53 | app.listen(port, function (err) {
|
54 | if (err) {
|
55 | console.log(err);
|
56 | return;
|
57 | }
|
58 |
|
59 | console.log(`Listening at http://localhost:${port}`);
|
60 | });
|