1.0.9 • Published 3 years ago

secured-rest-api v1.0.9

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

Integrated with some security related packages to get secure REST api

Integrated Packages :

CORS
HELMET
EXPRESS RATE LIMIT
MORGAN
ROTATING FILE STREAM
UUID

Install :

npm i secured-rest-api

Usage :

const {
    helmet,
    cors,
    expressRequestRate,
    morganLogger,
    ApiKey
} = require("secured-rest-api")

const express = require("express")

const app = express()

//Secure your app from hackers

app.use(helmet())

//Apply Cross origin resource sharing

app.use(cors())

//Access logging for the API

app.use(morganLogger('10M', '7d', './log'))

//Prevent API from getting multiple hits which may leads to server crash, DOS attack.

app.use(expressRequestRate(1, 10))

//Validate API's with keys

It reads x-api-key from request headers and validate with the key created in env process (auto assigned on creation, auto delete on expiry time)

//create Instance for ApiKey class

const apiKey = new ApiKey()

ApiKey Creation

const createKey = apiKey.create()

Options :

    Expiry time in seconds (Default 3600 seconds)

ApiKey Validation

app.use(apiKey.validate)