0.0.12 • Published 7 years ago

@lulea/http v0.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
7 years ago

Lulea HTTP

Lulea HTTP module provide HTTP management for your Node.js application. This module is based on the express framework. The particularity of this module is to create an HTTP server without any configuration. However, if you want to configure your server you can simply override all lulea configurations.

Getting started

Installation

    npm install --save @lulea/http

Create HTTP Server

In plain JavaScript

    const lulea = require('@lulea/http');
    const server = new lulea.Server();
    const router = lulea.Router();

    router.get('/', (req, res) => {
        return res.json({message: "Hello World!"});
    });

    server.routes(router);
    server.start();

In TypeScript

    import { Server, Router } from "@lulea/http";

    const server = new Server();
    const router = Router();

    router.get('/', (req, res) => {
        return res.json({message: "Hello World!"});
    });

    server.routes(router);
    server.start();

Default server options

Lulea gives you a preconfigured HTTP server with the following options that you can edit at any time in server configuration options:

Server

OptionDefault value
portprocess.env.PORT or "3000"

Body parser

OptionDefault value
enabletrue
urlEncoded.enabletrue
urlEncoded.extendedfalse
urlEncoded.inflatetrue
urlEncoded.limit"100kb"
urlEncoded.parameterLimit1000
urlEncoded.type"application/x-www-form-urlencoded"
json.enabletrue
json.inflatetrue
json.limit"100kb"
json.stricttrue
json.type"application/json"
raw.enablefalse
raw.inflatetrue
raw.limit"100kb"
raw.type"application/octet-stream"
text.enablefalse
text.defaultCharset"utf-8"
text.inflatetrue
text.limit"100kb"

Morgan

OptionDefault value
enabletrue
format"combined

Built-in API endpoints

Lulea provides built-in API endpoints that you can enable or disable at any time in server configuration options

  GET /health 
  {
    "status": "up",
    "uptime": 13.012
  }
  GET /infos (disable by default)
  {
    "os": {
      "arch": "x64",
      "platform": "linux"
    },
    "app": {
      "pid": 21263
    }
  }
  GET /metrics (disable by default)
  {
    "cpu": {
      "user": 428000,
      "system": 32000
    },
    "memory": {
      "rss": 43487232,
      "heapTotal": 21590016,
      "heapUsed": 14689264,
      "external": 650929
    }
  }

Overload default server options

const options = {
  port: "3000",
  bodyParser: {
    enable: true,
    urlEncoded: {
      enable: true,
      extended: false,
      inflate: true,
      limit: "100kb",
      parameterLimit: 1000,
      type: "application/x-www-form-urlencoded"
    },
    json: {
      enable: true,
      inflate: true,
      limit: "100kb",
      strict: true,
      type: "application/json"
    },
    raw: {
      enable: false,
      inflate: true,
      limit: "100kb",
      type: "application/octet-stream"
    },
    text: {
      enable: false,
      defaultCharset: "utf-8",
      inflate: true,
      limit: "100kb"
    }
  },
  morgan: { enable: true, format: "combined" },
  builtInEndpoints: {
    healthEndpoint: true,
    infosEndpoint: false,
    metricsEndpoint: false
  }
};
const server = new Server(options);
0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago