This is not just a fix for the issues inside handlers.ts it's an overall refactoring
- Use ES6 variable declaration i.e instead of
var
, we uselet
andconst
(var
is not scope safe)
- smaller functions inside handle.ts
- use of types
- getting rid of CPS (callbacks) and use async/await (promisify http request calls)
- Use
promise.AllSettled()
to provide parallel http calls incomputeResource()
.
Here i wanted to introduce the screaming architecture, just like nestjs
, you can see
that my folder structure and my code exposes the business objective not the layers of
the architecture.
handle.ts
has to have single concern, so a redesign needed:- add generic http request method to handle http calls in
utils
directory - group all pokemon related concerns inside the pokemon module directory
- the
getPokemonByName
endpoint should only return on response in my opinion, so i split it into two routes - use fastify middleware to validate incoming requests
- add generic http request method to handle http calls in
- Added
swagger
zod
to provide the schemas
- Makefile to facilitate interacting with project
- Multi-stage (faster build time) Dockerfile to kill environment dependency pain and
make sure you have node.js version 16 installed please
-
run:
-
m dkr-build m dkr-run
-
-
open swagger docs at
http://localhost:3000/docs
- install packages
m install
- run
m dev
- open swagger docs at
http://localhost:3000/docs
m test