@ducksclan/wrapper-express
v0.1.1
Published
this is wrapper for express based app
Downloads
2
Readme
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;