openapi-connect
Version:
Base for microservices around OpenAPI/Swagger
24 lines • 1.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const connect = require("connect");
const https = require("https");
const http = require("http");
const swaggerTools = require("@targetprocess/swagger-tools");
const gracefulShutdown = require("./gracefulShutdown");
const registrator_1 = require("./middleware/core/registrator");
exports.default = (spec, options) => {
const app = connect();
initialize(spec, app, options);
const server = options.ssl.enable ? https.createServer(options.ssl, app) : http.createServer(app);
if (options.gracefulShutdown.enable) {
gracefulShutdown.enable(server, options.logger, options.gracefulShutdown.readinessProbe);
}
return server;
};
const initialize = (spec, app, options) => {
return swaggerTools.initializeMiddleware(spec, (swagger) => {
(0, registrator_1.registerMiddleware)(app, options, swagger);
app.use((err, req, res, next) => next());
});
};
//# sourceMappingURL=server.js.map