Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/varthanv/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
https://github.com/varthanv/express-header-middleware
backend expressjs middleware
Last synced: 16 days ago
JSON representation
A middleware for express js to validate your headers and abort the request with response when the criteria for the headers is not satisifed
- Host: GitHub
- URL: https://github.com/varthanv/express-header-middleware
- Owner: VarthanV
- Created: 2023-02-18T03:17:20.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-18T06:09:00.000Z (almost 2 years ago)
- Last Synced: 2024-11-08T00:52:18.615Z (2 months ago)
- Topics: backend, expressjs, middleware
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/express-header-middleware
- Size: 116 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```sh
npm i express-header-middleware --save
```## Usage
```js
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},
],
})
);app.get("/", (req, res) => {
res.send("fooo");
return;
});app.listen(3000, () => {
console.log(`⚡️[server]: Server is running at http://localhost:3000`);
});```
## Empty Case
```json
{
"error": "foo is required",
"errorCode": "FOO"
}
```## Regex pattern is not matched
```json
{
"error": "foo does'nt match the regex pattern /\\d+/",
"errorCode": "FOO"
}
```