This project provides a simple, customizable API proxy server written in TypeScript. It allows you to forward API requests from a client to a remote API server while hiding your API key. The proxy server supports different methods of passing the API key, such as query parameters, headers, or basic authentication.
- Customizable API key insertion methods (query, header, basic authentication)
- CORS support
- TypeScript implementation
- Easy setup and deployment
- Node.js (LTS version recommended)
- yarn
-
Clone the repository:
-
Change the current directory to the project root:
cd generic-api-proxy
-
Install the required dependencies:
yarn install
-
Copy the
.env.example
file to a new file named.env
: -
Edit the
.env
file and set the following environment variables:
API_BASE_URL
: The base URL of the target API (e.g.,https://api.example.com
)API_KEY
: Your secret API keyAPI_KEY_INSERTION_METHOD
: The method to use for passing the API key (query
,header
, orbasic_auth
)CORS_ALLOW_ORIGIN
: A comma-separated list of allowed origins for CORS (e.g.,http://localhost:3000,https://yourdomain.com
). Set to*
to allow any origin.
To start the server in development mode with auto-reloading, run:
yarn dev
To start the server in production mode, run:
yarn start
Once the server is running, you can make requests to the API proxy from your client-side application. The proxy server will forward your requests to the target API server and return the responses.
For example, if your proxy server is running on http://localhost:8080
, and you want to request an endpoint from the target API server at /users
, you would make a request to http://localhost:8080/users
.
The proxy server will automatically add the API key to your requests based on the specified method (query
, header
, or basic_auth
).
- Docker support
- Multiple API Keys for different routes
- Rate limiting requests
- Generic support to deploy to cloudflare workers, aws lambdas, azure functions
- Logging for metrics and telemetry
Contributions are welcome! Feel free to submit pull requests or open issues to help improve this project.
This project is licensed under the MIT License.