wizard-service v1.0.0
The Vets Wizard Service
How To Run Locally
npm install
npm start
Nodemon starts the local server which means that as soon as any changes are made, the server restarts with the most updated code.
Base Libraries
This repo serves as the blueprint for all microservices to be used in the system.
Contained in this blueprint are base libraries that are universal and used for all services. The list of these
libraries are as follows:
1. @the_vets/express-lib: Our wrapper of Express.
2. Swagger: Autogenerated API route documentation with interface that allows for easy lookup of parameters and testing locally.
3. @the_vets/winston-lib: In house logger library. Logging should take place at all levels of the API (controller, service, etc..).
4. dotenv: Utility that loads environment variables from a local .env
file. This file is included in the .gitignore
file for obvious reasons. Having this makes local development easier (easier to edit text file vs. manually inputting variables in run configuration) and will
eventually allow any CI/CD process to load variables easily.
5. eslint: Most popular JS/TS linter. Available in package.json
is a command to fix any errors the linter catches (assuming it can be fixed automatically).
TypeScript
Code should be written in .ts
files. When running npm run start
, a nodemon instance of the webserver is started. This will allow for changes in files to be tracked
and changed on the fly. On every change, nodemon will transpile the typescript code to javascript. Only .ts
files should be checked into git. All other "javascript-type" files are
being ignored in the .gitignore
file.
Swagger and package.json
Setup
Swagger is implemented in @the_vets/express-lib
. To activate it correctly, all route files should be in src/routes
.
The service name is configured as seen below (from app.ts
):
const app = vetsExpressApp(process.env.SERVICE_NAME || 'microservice-seed', routeFiles);
Swagger docs will be available at: {host}:{port}/api-docs
package.json
: Change the name, description and repo urls.
Adding Routes
To add new routes, create new route files in the routes
directory. Any new files need to be added to
app.ts
(add require statement). Swagger generates its documentation and UI from the jsdocs above each route.
In order for the docs to be rendered the @swagger
decorator has to be included. See example for exact details and structure..
2 years ago