-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathwebpack.dev.js
More file actions
111 lines (105 loc) · 2.79 KB
/
webpack.dev.js
File metadata and controls
111 lines (105 loc) · 2.79 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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 themeConfig = import("./src/server/theme.mjs");
let port = 9000;
// proxy is setup to make frontend and backend url same for local testing
let proxy = [
{
context: ["/api/hyperswitch-recon-engine"],
pathRewrite: { "^/api/hyperswitch-recon-engine": "" },
target: "",
changeOrigin: true,
},
{
context: ["/api"],
target: "http://localhost:8080",
pathRewrite: { "^/api": "" },
changeOrigin: true,
},
{
context: ["/themes"],
target: "",
changeOrigin: true,
},
{
context: ["/test-data/recon"],
target: "",
changeOrigin: true,
},
{
context: ["/test-data/analytics"],
target: "",
changeOrigin: true,
},
{
context: ["/dynamo-simulation-template"],
target: "",
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;
if (!domain || domain === "") {
domain = "default"; // Fallback to default if no domain is provided
}
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;
}
if (req.path.includes("/config/theme") && req.method == "GET") {
themeConfig
.then((result) => {
result.themeConfigHandler(req, res, false);
})
.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", "hyperswitch") },
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("hyperswitch"),
{ mode: "development", devServer: devServer },
]);