ezproxy

Cookie cutter http-proxy using http-proxy-middleware

Usage no npm install needed!

<script type="module">
  import ezproxy from 'https://cdn.skypack.dev/ezproxy';
</script>

README

ezproxy

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

const express = require('express')
const dotenv = require('dotenv').config();
const app = express()
const path = require('path')
const { createProxyMiddleware } = require('http-proxy-middleware')
const username = process.env.ID
const target = 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

const username = process.env.ID

Change the target to url

const target = 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

const http = require('http');
const connect = require('connect');
const { createProxyMiddleware } = require('http-proxy-middleware')
const app = connect();
const site = createProxyMiddleware({target: 'server URL and port', changeOrigin: true, logLevel: 'debug'});

app.use('/', site);


http.createServer(app).listen(3005);

Change the target to url

const site = createProxyMiddleware({target: 'server URL and port', changeOrigin: true, logLevel: 'debug'});