Skip to content

Instantly share code, notes, and snippets.

@mathisGarberg
Last active August 18, 2020 05:33
Show Gist options
  • Select an option

  • Save mathisGarberg/017af94865d3a57f12a5ba719db6bce7 to your computer and use it in GitHub Desktop.

Select an option

Save mathisGarberg/017af94865d3a57f12a5ba719db6bce7 to your computer and use it in GitHub Desktop.
const express = require('express');
class AppModel {
constructor(NAME) {
this.NAME = NAME;
this.appimage = express();
}
withSwagger(docName) {
const swaggerUi = require('swagger');
const swaggerDocument = require(docName);
this.appimage.use('/doc', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
return this;
}
build() {
return this.appimage;
}
}
const newApp = new AppModel('AppWithBuilderPattern').withSwagger('swaggerDoc').build();
const server = newApp.appimage.listen(8081, () => {
const host = server.address().address;
const port = server.address().port;
console.log(`Example application listening on ${port}`;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment