-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
41 lines (36 loc) · 1.11 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
const PORT = 3010;
const express = require('express');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const path = require('path');
const chalk = require('chalk');
const ip = require('ip');
const app = express();
const config = require('./webpack.config.development');
const compiler = webpack(config);
app.use(
webpackDevMiddleware(compiler, { publicPath: config.output.publicPath }),
);
app.get('*', (_, res) => {
compiler.outputFileSystem.readFile(
path.join(compiler.outputPath, 'index.html'),
(err, file) => {
if (err) {
res.sendStatus(404);
} else {
res.send(file.toString());
}
},
);
});
app.listen(PORT, () => {
console.log(`Server started ! ${chalk.green('✓')}`);
console.log(`
${chalk.bold('Access URLs:')}
${chalk.gray('-----------------------------------')}
Localhost: ${chalk.magenta(`http://localhost:${PORT}`)}
LAN: ${chalk.magenta(`http://${ip.address()}:${PORT}`)}
${chalk.gray('-----------------------------------')}
${chalk.blue(`Press ${chalk.italic('CTRL-C')} to stop`)}
`);
});