@krknet/http-server

2.3.0 • Public • Published

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 ()

Readme

Keywords

none

Package Sidebar

Install

npm i @krknet/http-server

Weekly Downloads

10

Version

2.3.0

License

ISC

Unpacked Size

7.36 kB

Total Files

4

Last publish

Collaborators

  • krknet