Skip to content

Instantly share code, notes, and snippets.

@hypeJunction
Created March 22, 2019 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hypeJunction/45fb564118ee2ad830abbec83ee76f28 to your computer and use it in GitHub Desktop.
Save hypeJunction/45fb564118ee2ad830abbec83ee76f28 to your computer and use it in GitHub Desktop.
export default class App {
constructor (services) {
this.services = services;
}
start () {
const { express, db } = this.services;
if (!db.models) {
db.loadModels(this.services);
}
express.set('services', this.services);
express.use(async (request, response, next) => {
const { User } = db.models;
// This is pseudocode, we have a session service that reads user it from JWT token
response.locals.user = await User.findByPk(request.headers['X-User-Id']);
next();
});
return express;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment