I'm using express with express-http-proxy as a proxy for some of my applications. I have specific subdomains as part of my application that I want to get the value of.
For example, I make a request to my proxy via curl
curl google.com --proxy https://subdomainX.localhost:8000
I want to read the value of subdomainX. However, the Express request only has the url and host values of the domain I am proxying to (google.com in this case).
I want to read the req of my own server if this is possible.
This is the following sample server code:
import express from "express";
import proxy from "express-http-proxy";
const proxyApp = express();
proxyApp.use((req, res, next) => {
// I'd like to get the subdomain subdomainX here
// so I can perform logic with it
const subdomain = req.headers.host // this is google.com
if (subdomain === "subdomainX") {
next();
return;
}
res.send("Not authorized");
});
proxyApp.use(
proxy(
(req) => {
return req.protocol + "://" + req.get("host");
},
{
https: true,
}
)
);