Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEB _ FE_45_최승현 과제 제출 #898

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions my-agora-states-server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ const morgan = require('morgan');

// morgan 미들웨어가 세팅되어 있습니다.
// HTTP 요청 logger를 편리하게 사용할 수 있는 미들웨어 입니다.
app.use(morgan('tiny'));
app.use(morgan('tiny')), cors(), express.json({ strict:false })

// TODO: cors를 적용합니다.
app.use(cors())
app.use(express.json())
app.use(morgan('tiny'))


// TODO: Express 내장 미들웨어인 express.json()을 적용합니다.


const port = 4000;
const discussionsRouter = require('./router/discussions');

app.use('/discussions', discussionsRouter)
// TODO: app.use()를 활용하여 /discussions 경로로 라우팅합니다.


Expand Down
13 changes: 10 additions & 3 deletions my-agora-states-server/controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@ const discussionsData = agoraStatesDiscussions;
const discussionsController = {
findAll: (req, res) => {
// TODO: 모든 discussions 목록을 응답합니다.
res.send('TODO:')
return res.status(200).json(discussionsData)
},

findById: (req, res) => {
// TODO: 요청으로 들어온 id와 일치하는 discussion을 응답합니다.
res.send('TODO:')
const params = req.params.id;
const list = discussionsData.filter((data)=>data.id===Number(params))
console.log(list)
if(list.length !== 0){
return res.status(200).json(list[0]);
} else {
return res.status(404).json('n')
}
}
};

};

module.exports = {
discussionsController,
Expand Down
7 changes: 4 additions & 3 deletions my-agora-states-server/router/discussions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
const { discussionsController } = require('../controller');
const { findAll, findById } = discussionsController;
const express = require('express');
const { app } = require('../app');
const router = express.Router();

// TODO: 모든 discussions 목록을 조회하는 라우터를 작성합니다.


// TODO: 모든 discussions 목록을 조회하는 라우터를 작성합니다.
router.get('/',findAll)
// TODO: :id에 맞는 discussion을 조회하는 라우터를 작성합니다.
router.get('/:id',findById)


module.exports = router;
62 changes: 31 additions & 31 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"dependencies": {
"cors": "^2.8.5",
"dompurify": "^2.3.8",
"express": "^4.17.1",
"express": "^4.18.2",
"jsdom": "^19.0.0",
"morgan": "^1.10.0"
},
Expand Down