Study Case to figure out a simple way to have dependency injection and dependency inversion principle using only functions (not classes here, sorry OOP guys).
This API makes usage of a external service that generates random names, see more in: Named API and Named Web.
Easy peasy lemon squeezy:
$ yarn
Or:
$ npm install
Was installed and configured the
eslint
andprettier
to keep the code clean and patterned.
First, create a project into Firebase, then create a database.
Create a service account:
Then save it in src\config\service-account.json
.
There is a script (scripts/main.js
) that setup a feature flag required by the application, to run:
$ node scripts/main.js
Now your are ready to go
Improve the development velocity running the watch
script to rebuild the project everytime a file in src
folder changes.
npm run watch
Or:
yarn watch
Then you can just run the
serve
script once.
Run the build
script:
npm run build
Or:
yarn build
Then you are ready to start the server:
npm run serve
Or:
yarn serve
npm run deploy
Or:
yarn deploy
Deploy the functions is very easy, but is requires a Blaze (pay-as-you-go) plan.
route | HTTP Method | params | description |
---|---|---|---|
/featureFlags |
GET | - | Returns all flags in the database. |
/featureFlags/:key |
GET | key of the flag. |
Returns the specified flag. |
/randomNames |
GET | - | Returns random names in raw text or in base64 format (depends if the flag is enable or not). |
Jest was the choice to test the app, to run:
$ yarn test
Or:
$ npm run test
Run the command in the root folder
You can see the coverage report inside tests/coverage
. They are automatically created after the tests run.