-
Notifications
You must be signed in to change notification settings - Fork 354
/
dev-server.js
51 lines (42 loc) · 1.47 KB
/
dev-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
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
const webpack = require('webpack');
const devMiddleware = require('webpack-dev-middleware');
const hotMiddleware = require('webpack-hot-middleware');
const ip = require('ip');
const open = require('open');
const config = require('./webpack.config-5.dev');
const app = express();
const compiler = webpack(config);
app.use(
devMiddleware(compiler, {
publicPath: config.output.publicPath,
}),
);
app.use(hotMiddleware(compiler));
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.use('/i18n', express.static(path.resolve(__dirname, 'i18n')));
app.use('/assets', express.static(path.resolve(__dirname, 'assets')));
app.use('/core', express.static(path.resolve(__dirname, 'lib/core')));
app.get('/', (req, res) => {
res.sendFile(path.resolve(__dirname, 'src/index.html'));
});
const sampleURL = encodeURIComponent(JSON.stringify('https://pdftron.s3.amazonaws.com/downloads/pl/demo-annotated.pdf'));
app.get('/sample-url', (req, res) => {
res.redirect(
`/#d=${sampleURL}&a=1`,
);
});
app.listen(3000, '0.0.0.0', err => {
if (err) {
console.error(err);
} else {
// eslint-disable-next-line
console.info(`Listening at localhost:3000 (http://${ip.address()}:3000)`);
open(
`http://localhost:3000/#d=${sampleURL}&a=1`,
);
}
});