-
Notifications
You must be signed in to change notification settings - Fork 28
/
webpack.dev.js
75 lines (69 loc) · 1.84 KB
/
webpack.dev.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const path = require("path");
const webpack = require("webpack");
const { merge } = require("webpack-merge");
const common = require("./webpack.common.js");
const config = import("./src/server/config.mjs");
const appName = process.env.appName;
const integ = process.env.integ;
let port = 9000;
// proxy is setup to make frontend and backend url same for local testing
let proxy = {
"/api": {
target: "http://localhost:8080",
pathRewrite: { "^/api": "" },
changeOrigin: true,
},
};
let configMiddleware = (req, res, next) => {
if (req.path.includes("/config/feature") && req.method == "GET") {
let { domain = "default" } = req.query;
config
.then((result) => {
result.configHandler(req, res, false, domain);
})
.catch((error) => {
console.log(error, "error");
res.writeHead(500, { "Content-Type": "text/plain" });
res.end("Internal Server Error");
});
return;
}
if (req.path.includes("/config/merchant") && req.method == "POST") {
let { domain = "default" } = req.query;
config
.then((result) => {
result.merchantConfigHandler(req, res, false, domain);
})
.catch((error) => {
console.log(error, "error");
res.writeHead(500, { "Content-Type": "text/plain" });
res.end("Internal Server Error");
});
return;
}
next();
};
let devServer = {
static: {
directory: path.resolve(__dirname, "dist", appName),
},
compress: true,
hot: true,
port: port,
historyApiFallback: {
rewrites: [{ from: /^\/dashboard/, to: "/index.html" }],
},
proxy: proxy,
setupMiddlewares: (middlewares, devServer) => {
devServer.app.use(configMiddleware);
return middlewares;
},
};
console.log(devServer);
module.exports = merge([
common(appName),
{
mode: "development",
devServer: devServer,
},
]);