Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Route{
  2.     constructor(locals){
  3.         this.sql = locals.sql;
  4.         this.logger = locals.logger;
  5.         this.token = locals.config.token;
  6.     }
  7.     _checkAuth(){
  8.         let clientToken = this.req.headers['authorization'].replace('Bearer', '');
  9.         if (this.token === clientToken){
  10.             return true;
  11.         }
  12.         return false;
  13.     }
  14.     send(status = 200, data = {}){
  15.         this.res.status(status).send(data);
  16.     }
  17.     exec(){}
  18.     run(req, res){
  19.         this.req = req;
  20.         this.res = res;
  21.         if(this._checkAuth){
  22.             this.exec()
  23.         }else{
  24.             this.send(400);
  25.         }
  26.     }
  27. }
  28. module.exports = Route;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement