Here is the nodejs proxy server that can be use to listen subdomain routes.
for example I run a server is localhost:5000 but I want to use subdomain in this like subdomain1.localhost:5000 or something diferent.
const express = require('express'); const app = express(); const httpProxy = require('http-proxy'); const proxy = httpProxy.createProxy(); const BASE = "https://github.com"; app.use((req, res, next) => { const hostname = req.hostname; const domains = hostname.split('.'); const subdomain = domains[0]; const resolveTo = BASE '/' subdomain; return proxy.web(req, res, { target: resolveTo, changeOrigin: true }); }); app.listen(5000, () => console.log('Listening on port: 5000')); app.get('/', (req, res) => { return res.send('Welcome to the homepage'); });
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3