Created
July 23, 2020 16:04
-
-
Save nkhil/7ff5e0142db0ee530a077463fec7dee4 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
'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