add proxy to local env to mimic deploy environment

This commit is contained in:
Maxime Cannoodt 2022-07-03 15:24:27 +02:00
parent e3e4b3ccdd
commit eeaa98fa09
3 changed files with 1464 additions and 1 deletions

1433
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,13 @@
{
"scripts": {
"dev": "concurrently -n plugin,webapp,server \"npm --prefix ./plugin run dev\" \"npm --prefix ./webapp run dev\" \"npm --prefix ./server run dev\""
"proxy": "node proxy.js",
"dev": "concurrently -n plugin,webapp,server,proxy \"npm --prefix ./plugin run dev\" \"npm --prefix ./webapp run dev\" \"npm --prefix ./server run dev\" \"npm run proxy\""
},
"dependencies": {
"concurrently": "^7.2.2"
},
"devDependencies": {
"express": "^4.18.1",
"http-proxy-middleware": "^2.0.6"
}
}

25
proxy.js Normal file
View File

@ -0,0 +1,25 @@
const express = require("express");
const { createProxyMiddleware } = require("http-proxy-middleware");
const app = express();
app.use(
"/api/",
createProxyMiddleware({
target: "http://localhost:8080",
changeOrigin: true,
})
);
app.use(
"/",
createProxyMiddleware({
target: "http://localhost:3000",
changeOrigin: true,
})
);
app.listen(5000);
console.log("Reverse proxy listening at http://localhost:5000");
// http://localhost:3000/api/foo/bar -> http://www.example.org/api/foo/bar