Skip to content

Commit

Permalink
fix server config
Browse files Browse the repository at this point in the history
  • Loading branch information
SuaYoo committed Jan 8, 2025
1 parent 99a0edc commit 227e011
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions frontend/scripts/serve.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
// Serve app locally without building with webpack, e.g. for e2e
const fs = require("fs");
const path = require("path");
Expand All @@ -15,23 +16,36 @@ require("dotenv").config({
path: dotEnvPath,
});

const [devConfig] = require("../webpack.dev.js");
const devConfigs = require("../webpack.dev.js");
const [devConfig] = devConfigs;

const app = express();

const { devServer } = devConfig;
/** @type {import('webpack').Configuration['devServer']} */
const devServer = devConfig.devServer;

devServer.setupMiddlewares([], { app });
if (!devServer) {
throw new Error("Dev server not defined in `webpack.dev.js`");
}

if (devServer.setupMiddlewares) {
// @ts-ignore Express app is compatible with `Server`
devServer.setupMiddlewares([], { app });
}

if (Array.isArray(devServer.proxy)) {
devServer.proxy.forEach((proxy) => {
app.use(
// @ts-ignore
proxy.context,
createProxyMiddleware({
...proxy,
followRedirects: true,
}),
);
});
}

Object.keys(devServer.proxy).forEach((path) => {
app.use(
path,
createProxyMiddleware({
...devServer.proxy[path],
followRedirects: true,
}),
);
});
app.use("/", express.static(distPath));
app.get("/*", (req, res) => {
res.sendFile(path.join(distPath, "index.html"));
Expand Down

0 comments on commit 227e011

Please sign in to comment.