daily pastebin goal
70%
SHARE
TWEET

Untitled

a guest Feb 16th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import express from 'express';
  2. import { createConnection } from 'typeorm';
  3. import { ErrorHandler } from './controllers/ErrorHandler';
  4. import { user } from './routes/User';
  5.  
  6. class Server {
  7.   public express: express.Application;
  8.  
  9.   constructor() {
  10.     this.express = express();
  11.     this.express.set('port', process.env.APP_PORT || 3000);
  12.     this.express.use(express.json());
  13.     this.express.use('/auth/registration', user);
  14.     this.express.use(ErrorHandler);
  15.   }
  16. }
  17.  
  18. export default new Server().express;
  19.    
  20. import express from 'express';
  21. import {register } from '../controllers/User';
  22. import { UserRegistration } from '../entities/jsonschemas/UserRegistration';
  23.  
  24. const { Validator } = require('express-json-validator-middleware');
  25. const validator = new Validator({allErrors: true});
  26. const validate = validator.validate;
  27.  
  28. export const user = express.Router();
  29.  
  30. user.post('/', validate({body: UserRegistration}), register);
  31.    
  32. export const register = (err: any, req: any, res: any, next: any) => {
  33.   if (err) return next(err);
  34.   res.status(200);
  35.   res.json({});
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top