Skip to content

Extracted copy of AdonisJs HTTP server along with it's router

License

Notifications You must be signed in to change notification settings

RomainForks/http-server

 
 

Repository files navigation

Http Server

circleci-image npm-image license-image

Node.js HTTP server with a slick router used by AdonisJs. Think of it as an ExpressJs style server written in Typescript.

Table of contents

Usage

Install the package from npm registry as follows:

npm i @adonisjs/http-server

# yarn
yarn add @adonisjs/http-server

and then use it as follows:

import proxyaddr from 'proxy-addr'
import { createServer } from 'http'
import { Logger } from '@adonisjs/logger/build/standalone'
import { Profiler } from '@adonisjs/profiler/build/standalone'
import { Server } from '@adonisjs/http-server/build/standalone'

const logger = new Logger({ enabled: false, level: 'trace', name: 'adonis' })
const profiler = new Profiler({})
const config = {
  etag: false,
  jsonpCallbackName: 'callback',
  cookie: {},
  subdomainOffset: 2,
  generateRequestId: false,
  secret: Math.random().toFixed(36).substring(2, 38),
  trustProxy: proxyaddr.compile('loopback'),
  allowMethodSpoofing: false,
}

const server = new Server({} as any, logger, profiler, config)
server.optimize()

createServer(server.handle.bind(server)).listen(3000)

Router

AdonisJs has one of the most advanced and fast router. It has support for Route groups, Resourceful resources and many more.

router.group(() => {
  router.get('/', async () => {
  })
}).prefix('v1')

Profiler action labels

Following is the list of actions profiled during an HTTP request

  • http:request
  • http:before:hooks
  • http:route:match
  • http:route:stack
  • http:after:hooks
  • http:route:handler

We recommend you to check the API docs to get a complete reference of all the classes.

API

Following are the autogenerated files via Typedoc

Maintainers

Harminder virk

About

Extracted copy of AdonisJs HTTP server along with it's router

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 99.9%
  • JavaScript 0.1%