Last active
August 18, 2020 05:33
-
-
Save mathisGarberg/017af94865d3a57f12a5ba719db6bce7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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