This is design to be a cookie cutter proxy server ready to go. If you need detail on how to use http-proxy-middleware, please visit [http-proxy-middleware] (https://www.npmjs.com/package/http-proxy-middleware). Shelljs and dotenv is loaded for your convenience.
Example: Proxy for API
Copy and Paste
constexpress=require('express')constdotenv=require('dotenv').config();constapp=express()constpath=require('path')const{ createProxyMiddleware }=require('http-proxy-middleware')constusername=process.env.IDconsttarget=createProxyMiddleware({target: 'server URL and port',ChangeOrigin: true,auth: username,loglevel: 'debug'})app.use('Local server URI like /data/api',target);app.use(express.static('public'))app.get('/',function(req,res){res.sendFile(path.resolve(__dirname,'html file to be send to user for example index.html'))})app.listen(3001)
Go to each of these line and just change the variable
Use to hide the username and password
constusername=process.env.ID
Change the target to url
consttarget=createProxyMiddleware({target: 'server URL and port',ChangeOrigin: true,auth: username,loglevel: 'debug'})
Change the URI to what you want
app.use('Local server URI like /data/api',target);\
Create a public folder
app.use(express.static('public'))
Change the file name
app.get('/',function(req,res){res.sendFile(path.resolve(__dirname,'html file to be send to user for example index.html'))})
Change the port number
app.listen(3001)
Example: web proxy
Copy and Paste
consthttp=require('http');constconnect=require('connect');const{ createProxyMiddleware }=require('http-proxy-middleware')constapp=connect();constsite=createProxyMiddleware({target: 'server URL and port',changeOrigin: true,logLevel: 'debug'});app.use('/',site);http.createServer(app).listen(3005);
Change the target to url
constsite=createProxyMiddleware({target: 'server URL and port',changeOrigin: true,logLevel: 'debug'});