@krknet/http-server
v2.3.0
Published
Wrapper around Express
Downloads
19
Readme
HTTP-Server
Wrapper around Express
Usage
const HTTPserver = require('@krknet/http-server')
const httpServer = new HTTPserver({
port: 8080,
ApiRouter: require('./api'),
PagesRouter: require('./frontend')
})
await httpServer.start()
await httpServer.stop()
const router = new HTTPserver.Router()
Options
{
port: 8080, // Port - required
host: '127.0.0.1', // Host - optional
ApiRouter, // ApiRouter Class - required
PagesRouter, // PagesRouter Class
loadingPage: null, // Path to the Page Displayed during Initializing
sentryRequests: null, // Sentry HTTP Request Handler
onBeforeErrorHandlers: async () => null, // Sentry HTTP Request Handler
sentryErrors: null, // Sentry HTTP Error Handler
doTrustProxy: false, // enable('trust proxy')
doLogAPI: false, // Morgen Request Logger for API Endpoints
doLogFrontend: false, // Morgen Request Logger for Frontend Endpoints
bodyParserOptions: {}, // Options for BodyParser
helmetOptions: { contentSecurityPolicy: false }, // Options for Helmet
onStart: async () => null, // Executed and waited for an Start
initialMiddlewares: [], // Middlewares before all Parsers { route: '/', handler: (req, res, next) => next() },
middlewares: [], // Middlewares { route: '/', handler: (req, res, next) => next() },
statics: [] // Static Endpoints { route: '/static/', path: path.join(global.__basePath, 'static') }
}
Functions
async start ()
get rawServer ()
async stop ()