This is a command line interface(CLI) tool that starts caching proxy server, it forwards requests tot he actual server and caches the responses. If the same request is made again, it will return the cahed response instead of forwarding the request to the server.
- Understanding how caches work
- Building a caching proxy server to cache responses from other servers
User should be able to start the caching proxy server by running a command like following:
```bash
caching-proxy --port <number> --origin <url>
```
-
--port is the port on which the caching proxy server will run.
-
--origin is the URL of the server to which the requests will be forwarded
-
Add headers to the response that indicate whether the response is from the cache or the server
X-Cache: HIT #If the response is from the origin server X-Cache: MISS ````
You should also provide a way to clear the cache by running a command like following:
```bash
caching-proxy --clear-cache
```
- Node Js
- Docker
- Redis
-
Clone the repository
git clone https://github.com/RyanKaleliGabriel/ProxyVault.git cd ProxyVault.git
-
Set Environment Variables: The github API requires authentication for certain request. To avoid rate limits, you can use a personal Github access token. Create a .env file and add the your access token.
REDIS_HOST=<your_redis_host> REDIS_PORT=<your_redis_port> PORT=<your_apps_port_number> URL=<your_main_server_url>
-
Running the CLI: Compile the typecript files then call it with the required arguements.
npm start node dist/caching-proxy.js --port <your_apps_port_number> --origin <your_main_server_url> #Clearing the cache node dist/caching-proxy.js --clear-cache
- [port] (required): The port on which the caching proxy server will run.
- [origin] (required): The URL of the server to which the requests will be forwarded..
- [clear-cache] (optional): Clears the cache.
-
Forwarding request to the origin server.
node dist/caching-proxy.js --port <your_apps_port_number> --origin <your_main_server_url>
-
Clearing the Cache
node dist/caching-proxy.js --clear-cache
-
Pull the image from docker hub
docker pull ryankaleligabriel/proxyvault-app
-
Build the image
docker build -t ryankaleligabriel/proxyvault-app .
-
Run the image
docker run --name <your_container_name> -d -p 3000
-
Check for your output
docker logs <your_container_name>
1. Initial Request
Caching proxy server is running on http://localhost:3000
Forwarding requests to origin server: https://dummyjson.com
Cache miss. Fetching from origin...
Data cached
2. Other requests
Caching proxy server is running on http://localhost:3000
Forwarding requests to origin server: https://dummyjson.com/products
Cache hit!
Data or web page will be displayed in json on http://localhost:3000 where the caching proxy server will start.