Forward Proxy with Express.js (typescript)

Viewed 198

I'm currently trying to get an express based application functioning within a kubarnetes environment. To achieve this however I need to set it up to utilize a forward proxy for any outbound requests the server makes (such as login validation).

I've looked at various proxy libaries (https://github.com/http-party/node-http-proxy, https://github.com/chimurai/http-proxy-middleware, https://github.com/villadora/express-http-proxy) but most seem concerned only with reverse proxying.

node-http-proxy has something that seems to be forward proxying but I don't really understand it and I'm unsure if it is actually a forward proxy. (nor do I really get how to then apply this to a express app)

schematically my set up code looks like this:

import express, {NextFunction, Request, Response} from "express";

const app = express();

// App-specific imports
import routes from "./routes";

app.use("/", routes);

app.use(async (err: Error, req: Request, res: Response, next: NextFunction) => {
    handleError(req, res, err).catch((error) => {
        logger.error(error);
        res.status(500).json({error: `Something broke! (${error})`});
        return;
    });
});

app.listen(PORT, () => {
    console.log(
        `App is running at ${PROTOCOL}://${HOST}:${PORT} in ${ENV} mode`
    );
    console.log("  Press CTRL-C to stop\n");
});

What would I need to add to get it to forward proxy via for example http://proxy.example.com:8888?

0 Answers
Related