https://github.com/hellowinkr012/youapiproxy
A Reverse Proxy implementation in Express.js
https://github.com/hellowinkr012/youapiproxy
basic-auth caching express-js node-js rate-limiting
Last synced: about 2 months ago
JSON representation
A Reverse Proxy implementation in Express.js
- Host: GitHub
- URL: https://github.com/hellowinkr012/youapiproxy
- Owner: hellowinkr012
- License: agpl-3.0
- Created: 2024-09-14T10:00:32.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-15T04:36:39.000Z (over 1 year ago)
- Last Synced: 2025-03-16T06:12:29.089Z (11 months ago)
- Topics: basic-auth, caching, express-js, node-js, rate-limiting
- Language: JavaScript
- Homepage:
- Size: 37.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Reverse Proxy Server in Express.js
#### This project is an Express.js-based reverse proxy server designed to handle requests and forward them to another server. It interfaces with the GitHub repository search API, efficiently managing incoming requests, optimizing performance, and enhancing security .
## Key Features:
1. **Rate Limiting**: Controls the number of API requests to prevent overload and ensure fair usage.
2. **API Caching**: Implements caching to minimize unnecessary API calls, improving response times, efficiency, and reducing latency.
3. **Basic Authentication**: Secures communication with the server through authentication mechanisms.
4. **Custom Logging Module**: Provides detailed logs of server activity for monitoring, debugging, and insights.
5. **Testing Support**: Includes unit and multiple tests for robust development.
## How to Run Locally:
1. Clone this repository to your local machine:
```bash
git clone
```
2. Navigate to the root directory of the project (where the `package.json` is located):
```bash
cd
```
3. Install dependencies:
```bash
npm install
```
4. Run the server in development mode:
```bash
npm run dev
```
5. Update the `.env` file to configure rate limiting and API caching according to your requirements:
```bash
DEFAULT_RATE_LIMIT=5 # Maximum number of requests allowed per user within the specified duration.
DEFAULT_RATE_LIMIT_DURATION=60000 # Time window for rate limiting in milliseconds (e.g., 60 seconds).
DEFAULT_API_CACHE_TTL=120000 # Time-to-live (TTL) for cached API responses in milliseconds (e.g., 2 minutes).
```
## Running Tests:
This project includes test scripts to ensure that both single and multiple requests work as expected. You can run them with the following commands:
- To run single tests:
```bash
npm run test:single
```
- To run multiple tests:
```bash
npm run test:multiple
```
## Endpoints:
1. **Repository Search**:
```bash
GET http://localhost:5000/repo?query=
```
## Search parameters:
1. query : String -> Any name to find repositories in GitHub for
## Example Usage:
#### In JavaScript:
```javascript
// Set up request headers
const myHeaders = new Headers();
// It is one of test credentials already added
const username = "admin";
const passowrd = "11111111";
// Base64-encode the username and password for Basic Authentication
const base64EncodedCredentials = btoa(`${username}:${password}`);
// Add the Authorization header using the Base64-encoded credentials
myHeaders.append("Authorization", `Basic ${base64EncodedCredentials}`);
// Define request options
const requestOptions = {
method: "GET",
headers: myHeaders,
redirect: "follow"
};
// Make the API request to the reverse proxy
fetch("http://127.0.0.1:5000/repo?query=Express", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error('Error:', error));
```