Skip to content

Simple NodeJS app that simulates a caching proxy server.

Notifications You must be signed in to change notification settings

AMR856/Caching-Proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Proxy Caching Server

A simple HTTP proxy server written in Node.js that forwards requests to an origin server, follows redirects, and caches responses on disk for faster subsequent access.

✨ Features

  • πŸ”€ Redirect handling: Automatically follows 301, 302, 303, 307, and 308 redirects.
  • πŸ’Ύ Response caching: Stores responses in a local cache-files directory for reuse.
  • ⚑ Cache hit optimization: Serves cached responses instantly with a custom X-Cache: HIT header.
  • 🧹 Cache clearing: Supports a --clear-cache flag to delete all cached files.
  • πŸ›‘οΈ Error handling: Returns appropriate status codes for too many redirects or bad gateways.

πŸ“¦ Installation

Clone the repo and install dependencies:

git clone https://github.com/your-username/proxy-cache-server.git
cd proxy-cache-server
npm install


## πŸš€ Usage

Run the server with:

```bash
node index.js --port=3000 --origin=http://dummyjson.com --redirect=10

Options

  • --port <number> Port to run the proxy server on. Default: 3000.

  • --origin <url> Origin server to forward requests to. Default: http://dummyjson.com.

  • --redirect The number of allowed redirections

  • --clear-cache Clears the cache and exits.

Examples

Start server on port 4000:

node index.js --port=4000 --origin=https://example.com

Clear cache:

node index.js --clear-cache

πŸ“‚ Project Structure

.
β”œβ”€β”€ index.js               # Main proxy server
β”œβ”€β”€ utils/
β”‚   └── cache-functions.js # Cache management utilities
β”œβ”€β”€ cache-files/           # Cached responses (auto-created)
└── package.json

βš™οΈ How It Works

  1. Incoming requests are mapped to the origin server.

  2. If a cached response exists, it is served immediately with headers restored.

  3. If no cache is found:

    • The request is proxied to the origin.
    • Redirects are followed if necessary.
    • The response is cached and sent back to the client.

Solution for Caching Proxy Project https://roadmap.sh/projects/caching-server

About

Simple NodeJS app that simulates a caching proxy server.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published