Skip to content

Commit

Permalink
add swagger docs
Browse files Browse the repository at this point in the history
  • Loading branch information
shobhamrj committed May 20, 2023
1 parent d8996b6 commit 718985b
Show file tree
Hide file tree
Showing 4 changed files with 286 additions and 10 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
const serverless = require('serverless-http');
const express = require('express');
const mongoose = require('mongoose');
const swaggerUi = require('swagger-ui-express')
const YAML = require('yamljs')
require('dotenv').config()

const app = express();
app.use(express.json());
const DB_URI = process.env.MONGO_URI
const swaggerDocument = YAML.load('./swagger.yaml')

mongoose.connect(DB_URI, { useUnifiedTopology: true, useNewUrlParser: true })
.then(() => console.log('Connected to MongoDB'))
.catch(e => console.log('Error connecting to MongoDB:', e))

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument))
app.use('/', require('./routes/urlRoutes'))

module.exports = app;
Expand Down
225 changes: 216 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"express": "^4.18.2",
"mongoose": "^7.2.0",
"serverless-http": "^3.1.1",
"serverless-offline": "^12.0.4"
"serverless-offline": "^12.0.4",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^4.6.3",
"yamljs": "^0.3.0"
},
"devDependencies": {
"chai": "^4.3.7",
Expand Down
Loading

0 comments on commit 718985b

Please sign in to comment.