Skip to content

Instantly share code, notes, and snippets.

@julioflima
Created September 5, 2020 05:58
Show Gist options
  • Save julioflima/aea3c814509fa45f795605ec5553a910 to your computer and use it in GitHub Desktop.
Save julioflima/aea3c814509fa45f795605ec5553a910 to your computer and use it in GitHub Desktop.
App in class to facilitate reuse.
const express = require('express');
const cors = require('cors');
const { errors } = require('celebrate');
module.exports = class App {
constructor(routes) {
this.routes = routes;
this.server = express();
this.middleware();
this.router();
}
middleware() {
this.server.use(
cors()
// origin: ''
);
this.server.use(express.json());
this.server.use(errors());
}
router() {
this.server.use(this.routes);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment