0.1.1 • Published 2 years ago

@ducksclan/wrapper-express v0.1.1

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

Wrapper express

This is wrapper for express based app

Getting started

You need to install this module as a dependency of your nodejs project with any package manager.

$ npm install @ducksclan/wrapper-express

or

$ yarn add @ducksclan/wrapper-express

Usage

This module allows to quickly create an express application with helmet, cors, cookie-parser and express-fingerprint middlewares. This module also provides an asynchronous request handler and tagging middleware that allows to collect ip address and fingerprint hash generated by express-fingerprint module.

// app.ts
import { initialization, taggingMiddleware } from '@ducksclan/wrapper-express';

let cookieSecret: string = 'secret';
let app = initialization(cookieSecret);

app.use(taggingMiddleware());

export default app;
// interfaces.ts

export interface UserLocals extends TaggedLoclas {
  user: User;
}
// saveUserMiddleware.ts
import { asyncMiddleware } from '@ducksclan/wrapper-express';
import { UserLocals } from './interfaces.ts';

const saveUserMiddleware = asyncMiddleware<any, UserLocals>(
  async (req, res, next) => {
    await repository.save(res.locals.user);
    next();
  }
);

export default saveUserMiddleware;

Links