A simple reverse proxy for routing hypertext files from different ports to http
This proxy requires any attached web server to reply with Status Code 200, meaning some tools may not function perfectly, i.e. React apps are required to be built before hosting.
- express
v4.18.2
- http-proxy
v1.18.1
- chalk
v4.1.2
- nodemon
v3.0.1
- typescript
v5.3.3
- ts-node
v10.9.1
- eslint
v8.56.0
- Clone this repository
- Open the repository in a terminal
- Install packages with:
npm install
- Modify the
routes.example.json
anddev-routes.example.json
files as needed. (more info under usage) - Rename the files to
routes.json
anddev-routes.json
respectively. - Create any necessary files in the
development
directory - Start the proxy with:
npm start
- Make your connection
If you want to use ESLint in your development scripts, remove the .eslintignore file.
Read Step 4 for basics,
A web route is written as following:
{
"url": "example.hostname.com", // The hostname to intercept.
"route": "localhost:3000" // The route to proxy clients to.
}
A dev route is written as following:
{
"url": "exampleapi.hostname.com", // The hostname to intercept
"context": "server.example.ts" // The name of the file to send clients to.
}
Adding multiple can be done the same for either routes file, follow the routes example file for a demonstration for both, just remember that the routes file uses "route" while the dev routes file uses "context".
Feel free to make a Pull request, my layout is rather simple,
everything related to the code is within the /src directory,
HTTP-PROXY
│ .gitignore
│ license
│ package-lock.json
│ package.json
│ readme.md
│ tsconfig.json
│
└───src - Contains all of the functional code/files
│ index.ts - The Main Script, contains all of the functions and methods to get the HTTP Proxy running.
│ types.ts - The Main Typing file for Typescript, contains the layouts for the route files.
│
├───development - Contains User API files.
│ │ server.example.ts - (Example) The User API script, referenced in `dev-routes.example.json`.
│ │
│ └───example - (Example) Contains User Library files for the API script.
│ test.ts - An Example Library File.
│
└───routes - Contains the routes.
dev-routes.example.json - An Example of the dev-routes file.
routes.example.json - An Example of the web routes file.
dev-routes.json - The File that the script reads to get dev-routes.
routes.json - The File that the script reads to get web-routes.