A lightweight proxy server built with ExpressJS that forwards HTTP requests to a target URL, adding authentication and logging.
- Forwards requests to a specified target URL via the
/proxyendpoint - Adds a Bearer Authorization token to outgoing requests
- Logs all requests and errors in JSON format
- Supports JSON request and response bodies
- Node.js v16+
- An API token for authentication
- Clone the repository.
- Install dependencies:
npm install- Create a
.envfile in the project root with the following content:
PORT = 3000
NODE_ENV = development
AUTH_TOKEN = your_token_hereStart the proxy server:
npm run startSend a request to the proxy endpoint:
POST /proxy?targetUrl=https://api.yourservice.com/endpoint
Body example:
{
"messages": [
{
"role": "role",
"content": "input"
}
],
"model": "example-ai",
"stream": false
}src/index.js: Main server entry pointsrc/config/env.js: Environment variable managementsrc/config/logger.js: Simple JSON logger