Awesome-Express-Api
Overview
Features
-
-
Table of contents
Installation
npm i awesome-express-api
Initialize
; const app = ;const pocInstance = app DatabaseLayer options; // Register resourcespocInstance // Start serverpocInstance;
Options
Custom response format at get route
The standard response format for a get route is a array with result objects. If you want additional fields in the response, you can specify a response builder and customize the response.
For usage pass a function with the following format to the responseBuilder-option:
Example
;
Validators
The following validators are available at the moment:
isString
minLength:NUMBER
maxLength:NUMBER
notEmpty
isBoolean
Access in requests
DatabaseLayer
Docker
Login to github docker to build and push new images
docker login docker.pkg.github.com -u USERNAME -p PRIVATETOKEN
Build new Image
- docker build -t docker.pkg.github.com/bobo-le/awesome-express-api/aea:TAG .
- docker push docker.pkg.github.com/bobo-le/awesome-express-api/aea:TAG
Kubernetes
Create a deployment with pods and service inside
kubectl create -f deployment.yaml
Update running pods with new image
kubectl set image deployment/DEPLOYMENTNAME LABELNAME=docker.pkg.github.com/bobo-le/awesome-express-api/aea:TAG --record
Scale Pods
- kubectl scale --replicas=COUNT -f deployment.yaml
- COUNT=0 menas stopping all
Apply new config
kubectl apply -f deployment.yaml
Create secret to pull image from private registry
- kubectl create secret docker-registry regcred --docker-server=docker.pkg.github.com --docker-username=USERNAME --docker-password=PRIVATETOKEN --docker-email=EMAIL
- "regcred" is the name of your secret. Used in deployment.yaml
Get URL for running service
- minikube service SERVICENAME --url
- the api is under this url reachable
Helm
When using helm, kubecl -f FILES doesnt work anymore out of the box. Instead use the following
Optionally using kubectl -f FILES
- helm template REPONAME -x .\templates\deployment.yaml
- this renders the template file with the correct values
- result can be piped to -f with the following line
- helm template REPONAME -x .\templates\deployment.yaml | kubectl -f -
Installing environment with helm
- helm install --name REPONAME HELMDIRECTORY
- the repo is available under the REPONAME property
Upgrading with helm
- helm upgrade REPONAME HELMDIRECTORY
- it uses rolling update