Skip to content

Instantly share code, notes, and snippets.

@nkhil
Created July 23, 2020 16:04
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 nkhil/7ff5e0142db0ee530a077463fec7dee4 to your computer and use it in GitHub Desktop.
Save nkhil/7ff5e0142db0ee530a077463fec7dee4 to your computer and use it in GitHub Desktop.
'use strict';
const express = require('express');
const cors = require('cors');
const path = require('path');
const { OpenApiValidator } = require('express-openapi-validator');
const config = require('./config');
const app = express();
const apiSpec = path.join(__dirname, `../definitions/${config.name}.yml`);
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
new OpenApiValidator({
apiSpec,
validateResponses: true,
operationHandlers: path.join(__dirname, './handlers'),
})
.install(app)
.then(() => {
app.use((err, _, res) => {
res.status(err.status || 500).json({
message: err.message,
errors: err.errors,
});
});
});
module.exports = app;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment