Skip to content

ilia-abbasi/caching-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

caching-proxy

The project assignment for roadmap.sh

URL of the assignment in roadmap.sh:
https://roadmap.sh/projects/caching-server

This CLI app starts a server that caches responses from the origin.
The origin host and the port that this app listens on is read from the command line options.
caching-proxy saves cached responses in redis.

Installation

  1. Clone the repository:

    git clone https://github.com/ilia-abbasi/caching-proxy.git
    cd caching-proxy
  2. Install dependencies:

    npm install
  3. Create the .env file inside the ./misc directory and set the variables:

    REDIS_URl=redis://127.0.0.1:6379

Usage

  1. Build the project:

    npm run build
  2. Run the server with:

    npm run start -- -- --port 4000 --origin example.com # This works on my machine
    npm run start -- --port 4000 --origin example.com # This is what internet says works
  3. You can also run the server using the file created by ./misc/shorten_command.ts:

    ./caching-proxy --port 4000 --origin example.com
  4. Send requests using Postman or your desired browser.

Options

  • -V, --version:
    Output the version number.

  • -h, --help:
    Display help for command.

  • -p, --port <port-number>:
    The port number which caching-proxy will be listening on. Default is 7575.

  • -o, --origin <host>:
    The host which the requests will be redirected to, and the host which its responses will be cached. Either this option or --clear-cache must be provided.

  • -C, --clear-cache:
    Clears all cache stored in redis. Either this option or --origin must be provided. This option overrides --origin.

Testing

Testing is done with jest.

  • Run all the tests with:

    npm run test
  • Run unit tests with:

    npm run test:units

E2E tests will be implemented later so there will be a difference between these two commands.

Dependencies

  • commander
  • dotenv
  • express
  • morgan
  • redis

Dev dependencies

  • @types/dotenv
  • @types/express
  • @types/jest
  • @types/morgan
  • @types/node
  • @types/redis
  • jest
  • nodemon
  • ts-jest
  • tsx
  • typescript

The source code is formatted with Prettier.


caching-proxy is licensed under the GPL-3.0 license.

About

A CLI app that caches responses

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors