I am trying to re-write path in a specific way, but can't get the result I desire, and can't seem to figure out what I am doing wrong.
I have the following setup:
I have apps.eugene-dev.com
point to my server.
On my server I have several apps running on different ports, and I want to proxy to them. For example I have airflow webserver running on port 8080
I want something like this:
apps.eugene-dev.com/airflow
~> apps.eugene-dev.com:8080/
apps.eugene-dev.com/airflow/some_path
~> apps.eugene-dev.com:8080/some_path
But I want the url in my broweser to stay as is. So in the example above, I would get responce from apps.eugene-dev.com:8080/some_path
, however, I would still see apps.eugene-dev.com/airflow/some_path
.
After trying several things and not able to achive this, I am starting to question if what I want is even possible. If its not then I will have to switch to a seperate subdomain per app.
What I've tried:
This works, but this limits me to one app per subdomain
const airflow_target = `apps.eugene-dev.com:8080`
const airflow_proxy_options = {
target: 'http://apps.eugene-dev.com:8080',
logLevel: 'debug',
}
app.use('/', createProxyMiddleware(airflow_proxy_options));
This removes the /airflow
from the path, but also makes the whole URL be the target url
const airflow_target = `apps.eugene-dev.com:8080`
const airflow_proxy_options = {
target: 'http://apps.eugene-dev.com:8080',
changeOrigin: true,
pathRewrite: {
'^/airflow/': '',
'^/airflow': '', // remove base path
},
logLevel: 'debug',
}
app.use('/airflow', createProxyMiddleware(airflow_proxy_options));
This keeps the URL as I want but also doesn't remove the /airflow
hence making the request wrong (ie ...:8080/airflow/login
instead of ...:8080/login
const airflow_target = `apps.eugene-dev.com:8080`
const airflow_proxy_options = {
target: 'http://apps.eugene-dev.com:8080',
changeOrigin: true,
logLevel: 'debug',
}
app.use('/airflow', createProxyMiddleware(airflow_proxy_options));
Am I wanting too much and this is just not how it works, or is there some way to combine these effects? As I said before, I don't strictly need this to work, I have other ways to acomplish my altimate task, but it just frustrates me so much, that I think it should work but it doesn't. So hoping to learn something new.
Thank you in advance!