base-hapi
A base hapi configuration for my new API projects
Pre-Requisites
- node 8.10 or greater
- npm 6.1.0 or greater
- redis 4.0 or greater
Usage
const baseConfig = ;async { const server = await baseConfig; await serverstart; console; // server started at http://localhost:4000};
If you want to change the HOST and PORT you can do it by setting up two variable environments
HOST=192.168.1.25PORT=2000
Configuration
Out of the box base-hapi comes with many defaults:
- Catbox Redis with the following configuration
name: processenvCATBOX_REDIS_NAME || 'catbox-redis' // engine: require(catbox-redis), partition: processenvCATBOX_PARTITION_NAME || 'cache' host: processenvREDIS_HOST || 'localhost' port: processenvREDIST_PORT || 6379
- Sentry for logging management. You will need an account here Now you can pass your sentry environment and dsn with these environment variables
options: environment: processenvNODE_ENV dsn: processenvSENTRY_DNS
- For authentication you must define a function with your logic inside of it.
{ // your custom validation here // return true to pass to the handler // return false to return a 401 to client // credentials can be used inside your handlers in the request object // request.auth.credentials return isValid: true credentials: id: 1 ;} const server = await ;
- Adding plugins
const myPlugin = name: 'my-plugin' { server; } version: '1.0.0';const plugins = myPlugin;const server = await ;
- The objection-paginate plugin is included.
const server = await ;server;
If you do not specify a limit in the query parameters it will use the OFFSET_DEFAULT environment variable
OFFSET_DEFAULT = 10