0.0.12 • Published 7 years ago
@lulea/http v0.0.12
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
Option | Default value |
---|---|
port | process.env.PORT or "3000" |
Body parser
Option | Default value |
---|---|
enable | true |
urlEncoded.enable | true |
urlEncoded.extended | false |
urlEncoded.inflate | true |
urlEncoded.limit | "100kb" |
urlEncoded.parameterLimit | 1000 |
urlEncoded.type | "application/x-www-form-urlencoded" |
json.enable | true |
json.inflate | true |
json.limit | "100kb" |
json.strict | true |
json.type | "application/json" |
raw.enable | false |
raw.inflate | true |
raw.limit | "100kb" |
raw.type | "application/octet-stream" |
text.enable | false |
text.defaultCharset | "utf-8" |
text.inflate | true |
text.limit | "100kb" |
Morgan
Option | Default value |
---|---|
enable | true |
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);