The purpose of this project is to create an HTTP proxy server to normalize requests with CORS and facilitate API interactions with any request method and on-the-fly modifications.
This project simplifies the development process by handling CORS issues and providing a flexible way to interact with APIs, making it easier to test and develop applications.
The project sets up a proxy server using Node.js that intercepts HTTP requests, adds the necessary CORS headers, and allows for modification of the request and response on the fly.
To install and run the project:
-
Clone the repository:
git clone https://github.com./Fulldroper/cors-proxy cd cors-proxy
-
Install dependencies and start the server:
npm install npm start
Make default requests to /
path and set header cors-url
with site url
For ignore headers set header cors-ignore
with array of headers will be deleted from request
all methods, headers, params duplicated automatically
- Create file
.env
- write
PORT=<Your port>
- Save changes
Change or add to file
.env
next lineENTERPOINT=/
Change or add to file
.env
next lineALOWED=GET, POST, PUT, DELETE
-
Setup Project: Initialize the project structure and dependencies.
npm init npm install
-
Create Proxy Server: Set up the proxy server with CORS handling.
const express = require('express'); const { createProxyMiddleware } = require('http-proxy-middleware'); const app = express(); app.use('/', createProxyMiddleware({ target: 'http://example.com', changeOrigin: true, onProxyReq: (proxyReq, req, res) => { // Modify request headers proxyReq.setHeader('X-Special-Proxy-Header', 'foobar'); }, onProxyRes: (proxyRes, req, res) => { // Modify response headers proxyRes.headers['X-Special-Proxy-Response-Header'] = 'baz'; } })); app.listen(3000, () => { console.log('CORS proxy server running on port 3000'); });
- Developing proxy servers with Node.js
- Handling CORS issues in web development
- Modifying HTTP requests and responses on the fly
More questions? mail me