5.2.0 • Published 5 years ago

@reperio/hapijs-starter v5.2.0

Weekly downloads
-
License
MPL-2.0
Repository
github
Last release
5 years ago

Coverage Status Build Status npm version

hapijs-starter

Configuration Options

Runs a fully-configured HAPI server with Winston logging.

Setup

All you need to do to run the server is to call it in an async method when your application starts.

import {Server} from 'hapijs-starter';
import * as path from 'path';

async function startServer() : Promise<void> {
    const server = new Server({});
    await server.initialize();
    await server.registerRoutesFromDirectory(path.resolve(__dirname, './api'));
    await server.startServer(false);
}

startServer();
PropertyTypeDefault ValueDetails
hoststring'0.0.0.0'HapiJS host binding
portnumber3000HapiJS port binding
corsbooleantrueAdds a global route for HTTP OPTIONS requests that responds with options headers to allow CORS requests
statusMonitorbooleantrueAdds the hapijs-status-monitor plugin that exposes a /status route to get basic server status information
defaultRoutebooleantrueAdds a default route that responds with 'hello' to be used for heartbeat requests from reverse proxies
logDirectorystring./logsdirectory to store file based logs
logLevelstring'debug'log level for winston logging
logJsonbooleantrueshould the logs be in JSON format?
logDefaultFileTransportbooleantrueAdd the default file transport to the logger
logDefaultConsoleTransportbooleantrueAdd the default console transport to the logger
logDefaultTraceTransportbooleantrueAdd the default trace transport to the logger
logAddtionalLoggerTransportsArray[]Additional transports to add to the app logger
logAddtionalTraceTranceportsArray[]Additional transports to add to the trace logger
logAutoTraceLoggingbooleantrueAutomatically log http requests to the trace log
authEnabledbooleanfalseEnable JWT authentication
authSecretstringnullJWT secret used to validate JWTs. Required if authEnabled === true
authValidateFunc(decoded: any, request: any, callback: any) => any;(decoded, request, callback) = { return { isValid: true };}Additional validation function based on hapi-auth-jwt2 validation function