-
Notifications
You must be signed in to change notification settings - Fork 14
/
server-proxy.js
49 lines (43 loc) · 1.28 KB
/
server-proxy.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
const url = require("url");
/*
Note: This app is for testing purposes only,
e.g. in order to run the vue client in a docker container on localhost
*/
const express = require("express");
const { createProxyMiddleware } = require("http-proxy-middleware");
const {
createLegacyClientProxy,
createServerProxy,
createFileStorageProxy,
createH5pEditorProxy,
} = require("./config/webpack/dev-server-config");
const {
isServer,
isFileStorage,
isH5pEditor,
} = require("./src/router/server-route");
const { isVueClient } = require("./src/router/vue-client-route");
const vueClientProxy = createProxyMiddleware({
target: "http://localhost:4000",
changeOrigin: true,
});
const legacyClientProxy = createLegacyClientProxy();
const serverProxy = createServerProxy();
const fileStorageProxy = createFileStorageProxy();
const h5pEditorProxy = createH5pEditorProxy();
const app = express();
app.use((req, res, next) => {
const path = url.parse(req.originalUrl).pathname;
if (isFileStorage(path)) {
fileStorageProxy(req, res, next);
} else if (isH5pEditor(path)) {
h5pEditorProxy(req, res, next);
} else if (isServer(path)) {
serverProxy(req, res, next);
} else if (isVueClient(path)) {
vueClientProxy(req, res, next);
} else {
legacyClientProxy(req, res, next);
}
});
app.listen(4242);