Skip to content

Commit

Permalink
Merge pull request #103 from boostcampwm-2024/feature/be/setup
Browse files Browse the repository at this point in the history
[BE][Docs] #82 : swagger ์„ค์น˜ ๋ฐ ์˜ˆ์‹œ ์ ์šฉ
  • Loading branch information
happyhyep authored Nov 6, 2024
2 parents 2750dfb + 193999b commit b2207be
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
4 changes: 3 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.21.1"
"express": "^4.21.1",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.1"
}
}
19 changes: 12 additions & 7 deletions backend/src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
const express = require('express');
import express from 'express';
import swaggerUi from 'swagger-ui-express';
import specs from '../swaggerConfig.js';

const app = express();
const port = process.env.PORT || 3000;
const port = 3001;

app.get('/', (req, res) => {
res.json({
success: true,
});
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs));

// ์˜ˆ์ œ ๋ผ์šฐํ„ฐ (์ถ”๊ฐ€ ์˜ˆ์ •์ธ ๋ผ์šฐํ„ฐ์˜ ์ฃผ์„์„ Swagger ์ฃผ์„ ํ˜•์‹์œผ๋กœ ๋ฌธ์„œํ™”)
app.get('/example', (req, res) => {
res.send('Hello World');
});

app.listen(port, () => {});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
13 changes: 13 additions & 0 deletions backend/src/routes/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @swagger
* /example:
* get:
* summary: Example endpoint
* description: Returns a simple "Hello World" message
* responses:
* 200:
* description: Successful response
*/
app.get('/example', (req, res) => {
res.send('Hello World');
});
24 changes: 24 additions & 0 deletions backend/swaggerConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import swaggerJSDoc from 'swagger-jsdoc';

const swaggerDefinition = {
openapi: '3.0.0',
info: {
title: 'Your API Name',
version: '1.0.0',
description: 'API documentation for Your Project',
},
servers: [
{
url: 'http://localhost:3001',
},
],
};

const options = {
swaggerDefinition,
apis: ['./routes/*.js'],
};

const specs = swaggerJSDoc(options);

export default specs;

0 comments on commit b2207be

Please sign in to comment.