New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@adonisjs/http-server

Package Overview
Dependencies
Maintainers
2
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@adonisjs/http-server

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

  • 1.6.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
21K
decreased by-29.67%
Maintainers
2
Weekly downloads
 
Created
Source

AdonisJS Http Server

Decently fast HTTP server used by AdonisJS

appveyor-image circleci-image typescript-image npm-image license-image

This module is extracted from the AdonisJS framework to work as a standalone HTTP server. The performance of the server is on par with Fastify (not as fast as fastify though).

Table of contents

Benchmarks

The benchmarking scheme is taken from the Fastify github repo.

Machine: Quad-Core Intel Core i7, 2.2GHz, 16GB RAM Method: autocannon -c 100 -d 40 -p 10 localhost:3000 * 2, taking the second average

FrameworkVersionRouter?Requests/sec
Fastify2.0.052709
AdonisJs1.5.447791

You can run the same benchmarks by cloning the repo and then running the following command.

npm run benchmark

Since the program correctness and reliability is more important over micro optimizations. We pay penality on following fronts in comparison to Fastify.

  • The AdonisJS query string parser can parse arrays inside query string (/api?foo[]=bar&foo[]=fuzz&foo[]=buzz ), wherease fastify doesn't parse it by default for performance reasons. However, you can also define your own query string parser with fastify, but again, you will end up paying the same performance penality.
  • Subdomain based routing is another front, where AdonisJS has to perform little bit extra work to find the correct route and it's handler.

Features

  • The most advanced router with support for route resources, route groups, subdomains routing.
  • Support for global and route specific middleware.
  • Reliable and stable query string parser.
  • Global exception handler to catch all exceptions handled during an HTTP request.
  • Sends data to AdonisJS inbuilt profiler

Usage

You must be using the server inside a fully fledged AdonisJS application. Still, here's how you can start the standlone server.

npm i @adonisjs/http-server
import proxyaddr from 'proxy-addr'
import { createServer } from 'http'
import { Ioc } from '@adonisjs/fold'
import { Logger } from '@adonisjs/logger/build/standalone'
import { Profiler } from '@adonisjs/profiler/build/standalone'
import { Encryption } from '@adonisjs/encryption/build/standalone'

import { Server } from '@adonisjs/http-server'

const logger = new Logger({ enabled: true, level: 'trace', name: 'adonis' })
const profiler = new Profiler({ enabled: true })
const encryption = new Encryption('averylongrandom32charslongsecret')

const server = new Server(new Ioc(), logger, profiler, encryption, {
  etag: false,
  jsonpCallbackName: 'callback',
  cookie: {},
  subdomainOffset: 2,
  generateRequestId: false,
  secret: Math.random().toFixed(36).substring(2, 38),
  trustProxy: proxyaddr.compile('loopback'),
  allowMethodSpoofing: false,
})

server.router.get('/', async () => {
  return { hello: 'world' }
})
server.optimize()

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

Keywords

FAQs

Package last updated on 14 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc