UNPKG

generator-kube-microservice-node

Version:

A k8s micro-service generator with deployment, service, Dockerfile. Built with express/mongo/redis

26 lines (25 loc) 864 B
import * as jwt from 'jsonwebtoken'; import UnprocessableEntityException from '../exceptions/UnprocessableEntityException'; import { Request } from 'express'; import { validationResult } from 'express-validator'; /** * Decodes a token from Authorization Header * * @returns [[UserInterface]] * @param jwtToken A authorization header */ export const decodeToken = <T>(jwtToken: string): T => { return jwt.decode(jwtToken.replace('Bearer ', '')); }; /** * Validates a request using express-validator * The valiation will be made against the inversify-express-utils decorator * If request has errors, it will throw a UnprocessableEntityException error */ export const validateRequest = (req: Request): void => { const errors = validationResult(req); if (!errors.isEmpty()) { throw new UnprocessableEntityException(errors.array()); } return; };