-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpackServe.js
47 lines (38 loc) · 1.37 KB
/
webpackServe.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
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const webpack = require('webpack');
const WebpackDevMiddleware = require('webpack-dev-middleware');
const examplesConfiguration = require('./webpack.examples.config');
const configurations = examplesConfiguration(
{...process.env, WEBPACK_SERVE: true},
process.argv
);
const SERVE_PORT = process.env.SERVE_PORT ? Number(process.env.SERVE_PORT) : 10555;
const SERVE_HOST = process.env.SERVE_HOST || 'localhost';
const SPARQL_ENDPOINT = process.env.SPARQL_ENDPOINT;
const WIKIDATA_ENDPOINT = process.env.WIKIDATA_ENDPOINT
?? 'https://query.wikidata.org/sparql';
const app = express();
for (const config of configurations) {
const compiler = webpack(config);
app.use(WebpackDevMiddleware(compiler, {
publicPath: config.output.publicPath,
}));
}
if (SPARQL_ENDPOINT) {
app.use(createProxyMiddleware('/sparql**', {
target: SPARQL_ENDPOINT,
pathRewrite: {'/sparql' : ''},
changeOrigin: true,
secure: false,
}));
}
app.use(createProxyMiddleware('/wikidata**', {
target: WIKIDATA_ENDPOINT || SPARQL_ENDPOINT,
pathRewrite: {'/wikidata' : ''},
changeOrigin: true,
secure: false,
}));
// eslint-disable-next-line no-console
console.log(`Running Webpack server at host: "${SERVE_HOST}", port: ${SERVE_PORT}`);
const server = app.listen(SERVE_PORT, SERVE_HOST);