Digital service to support the Ivory Act.
(Be sure to describe any environment variables here by maintaining a list like this)
name | description | required | default | valid | notes |
---|---|---|---|---|---|
NODE_ENV | Node environment | no | dev,test,prod | ||
PORT | Port number | no | 3010 |
Node v14+
First install the dependencies & build the application using:
$ npm install
Now the application is ready to run:
$ npm start
or $ node index.js
$ npm run docker:build
followed by $ npm run docker:run
Here's the default structure for the project files.
- server
- plugins
- routes
- config.js
- index.js (Exports a function that creates a server)
- test
- README.md
- index.js (startup server)
The configuration file for the server is found at server/config.js
.
This is where to put any config and all config should be read from the environment.
The final config object should be validated using joi and the application should not start otherwise.
A table of environment variables should be maintained in this README.
hapi has a powerful plugin system and all server code should be loaded in a plugin.
Plugins live in the server/plugins
directory.
The good and good-console plugins are included and configured in server/plugins/logging
The logging plugin is only registered in when NODE_ENV=dev
.
Error logging for production should use errbit.
Incoming requests are handled by the server via routes. Each route describes an HTTP endpoint with a path, method, and other properties.
Routes are found in the server/routes
directory and loaded using the server/plugins/router.js
plugin.
Hapi supports registering routes individually or in a batch. Each route file can therefore export a single route object or an array of route objects.
A single route looks like this:
{
method: 'GET',
path: '/hello-world',
options: {
handler: (request, h) => {
return 'hello world'
}
}
}
There are lots of route options, here's the documentation on hapi routes
lab and code are used for unit testing.
See the /test
folder for more information.
standard.js is used to lint both the server-side and client-side javascript code.
It's defined as a build task and can be run using npm run lint
.