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.
-
Clone the repository:
git clone https://github.com/ilia-abbasi/caching-proxy.git cd caching-proxy -
Install dependencies:
npm install
-
Create the
.envfile inside the./miscdirectory and set the variables:REDIS_URl=redis://127.0.0.1:6379
-
Build the project:
npm run build
-
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
-
You can also run the server using the file created by
./misc/shorten_command.ts:./caching-proxy --port 4000 --origin example.com
-
Send requests using Postman or your desired browser.
-
-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 is7575. -
-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-cachemust be provided. -
-C, --clear-cache:
Clears all cache stored in redis. Either this option or--originmust be provided. This option overrides--origin.
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.
- commander
- dotenv
- express
- morgan
- redis
- @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.