const express = require("express");
const { createProxyMiddleware, responseInterceptor } = require("http-proxy-middleware");
const port = 8080;
const app = express();
app.use(
createProxyMiddleware("/api/", {
target: "http://example.com/api/",
changeOrigin: true,
pathRewrite: {
"^/api": "",
},
selfHandleResponse: true,
onProxyRes: responseInterceptor(async (responseBuffer, proxyRes, req, res) => {
res.removeHeader("Access-Control-Allow-Origin")
res.setHeader("Access-Control-Allow-Origin", "*")
return responseBuffer
}),
})
);
app.use(express.static("dist"));
app.listen(port);
console.log("Server is running at http://localhost:" + port);
评论已关闭