Skip to content

Instantly share code, notes, and snippets.

@jsCommander
Created November 19, 2019 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsCommander/19bebe5d6ec0660f3d5a240b8c87eda1 to your computer and use it in GitHub Desktop.
Save jsCommander/19bebe5d6ec0660f3d5a240b8c87eda1 to your computer and use it in GitHub Desktop.
const express = require("express");
const proxy = require("express-http-proxy");
const path = require("path");
const app = express();
const api = "localhost:8080";
app.all(
"/api/*",
proxy(api, {
proxyReqPathResolver: req => {
const newUrl = req.url.replace("/route/service/method/", "/service/method/");
return newUrl;
},
})
);
const host = process.env.WEB_HOST;
const port = process.env.WEB_PORT;
app.listen(port, host, () => {
console.log(`proxy server listen at ${host}:${port}`);
console.log(`Api request redirected to ${api}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment