1.0.0 • Published 1 year ago

express-header-middleware v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

express-header-middleware

A middleware for express js to validate your headers and abort the request with response when the criteria for the headers is not satisifed

Installation

    npm i express-header-middleware --save

Usage

import express, { Express } from "express";

const app: Express = express();

app.use(
  headerMiddleware({
    headers: [
      {
        name: "foo",
        errorCode:"FOO",
        httpStatusCode:403, // optional, Default 400
        regExp:new RegExp("\\w+") // optional , Default none

      },

    ],
  })
);

app.get("/", (req, res) => {
  res.send("fooo");
  return;
});

app.listen(3000, () => {
  console.log(`⚡️[server]: Server is running at http://localhost:3000`);
});

Empty Case

{
  "error": "foo is required",
  "errorCode": "FOO"
}

Regex pattern is not matched

{
    "error": "foo does'nt match the regex pattern /\\d+/",
    "errorCode": "FOO"
}
1.0.0

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago