Orchestration server for the main Tupaia application
To run locally, run from the monorepo root:
yarn start-stack tupaia-webIf you want to connect to a local aggregation server/DHIS2 instance, clone the docker-dhis2 repository.
- Read DHIS2 Docker’s README.
./dhis-start.shto start Docker DHIS.
Entry point for the app, using Express. Initialises server and sets middlewares’ use:
morgan('dev')→ simple console loggerbodyParser→ auto parse request body as JSONcheckBadJson→ adequately deal with incorrect JSON requests (this should be tied in with error handler, and be logged via email)- After that, initialise database and continue →
authInit→ sets up cookie sessionsauth→ check each request for appropriate authorisation/api/v1, api_v1→ links router defined inapiV1to/api/v1- then start server and log port
Router is defined here, to introduce new route under /api/v1:
app.<get/post>('/routepath', routeFn()) where routeFn is in the format:
export default () => (req, res, next) => {
// Do something with req.body (as JSON)
// Send response via res.send(response JSON)
};Authentication functions.
| :--------- | :----------------------------------------------------------------------------------------------------------------------------- |
| authInit | first middleware for request, from 'client-sessions', deals with decrypting session and setting sessions further down the line |
API connect for Tupaia App server.
| :------------------------- | :---------------------------------------------------------------------- |
| auth | Second middleware for request, checks to see if session (cookie) exists |
| authLogin | Checks user’s password, username matches DB |
| authCreateUser | Creates a new user using a set of fields |
| authChangePassword | Changes the password of an existing user |
| authGetCountryAccessList | Gets the user’s access to the available countries |
| authRequestCountryAccess | Requests user access to specified countries |
Deals with OAuth 2 authentication and request from DHIS2.
- Start the server:
yarn start-dev. - Open the Debug tab and select
nodemonfrom the available configurations. - Click the green arrow to
Start Debugging. A list with currently running Node processes will pop up. Select the one that starts with--inspect=9999 - You are ready to start debugging! Add breakpoints to your code to inspect the program state. You can also enable breakpoints at
All Exceptionsto effectively debug errors.