- nodejs - javascript runtime built on v8 engine
- express - minimalistic web api framework for nodejs
- body-parser - middleware for body parsing
- morgan - middleware for http request/response logging
- jsonwebtoken - jwt implementation for nodejs
- crypto - cryptography module for nodejs
- jasmine - testing framework
- jasmine-reporters - test result reporters (using JUnit reporter for CircleCI)
- istanbul - module for test instrumentation and coverage
- request - module for testing end-points
- swagger-jsdocs - swagger docs
- swagger-ui-express - swagger UI
- clone repo and
npm install
- in the project directory, run
node index.js
- launch the browser and point to the baseurl
localhost:8081
(port can be changed inconfig.js
) - swagger api docs can be viewed at
/api-docs
- optional:
- use nodemon to monitor for changes in your nodejs app and automatically restart the server
- if you don't have nodemon, install it globally
npm install -g nodemon
- in the project directory run
nodemon
- tests are in the
spec
directory, which includes bothunit
andintegration
tests - to run all the tests, run
npm test
in the project directory - to run a single test, mark it with
fit
(usefdescribe
to include the entire spec) - to exclude a test, mark it with
xit
(usexdescribe
to exclude the entire spec) - test coverage:
- to run instrumented code and generage coverage reports, run
npm run test-with-coverage
- coverage reports are in
reports/coverage
directory (can be configured in.istanbul.yml
)
- to run instrumented code and generage coverage reports, run
- reporter runs a jasmine helper to produce JUnit formatted test results in
reports/junit
- access the unsecure api
GET /metacortex
- all
/api/*
calls are secured with JWT authentication - try accessing the secure api
GET /api/megacity
to see an auth error - obtain a JWT token here
POST /authenticate.html
- enter program name:password (neo:keanu or morpheus:laurence)
- the response contains a JWT token for that program
- use the token when calling any secure api (
/api/*
):- set the
Authorization
request header and add the jwt token, like so: Authorization: Bearer \<token\>
- set the
GET /api/megacity
can be accessed with any token butGET /api/levrai
can only be accessed with neo's token- some information in the payload is encrypted for privacy
- a part of the jwt claims/playload is encrypted before signing and then decrypted after verification for privacy
- this is different from JWE, where only the signature is encrypted while the claims/payload can be easily decoded and read
- a middleware that introduces
500 - Internal Server Error
errors randomly for any/oracle/*
api call - this chaos can be seen:
- by repeatedly accessing
GET /oracle/choice
or - by running this test:
/spec/integration/apiChaosSpec.js
- by repeatedly accessing