Created
November 19, 2019 08:21
-
-
Save jsCommander/19bebe5d6ec0660f3d5a240b8c87eda1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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