-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
34 lines (24 loc) · 945 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// DEV283X module 2 assignment lab: an express-based blog
const express = require('express')
const logger = require('morgan')
const errorhandler = require('errorhandler')
const bodyParser = require('body-parser')
const app = express()
app.use(bodyParser.json())
app.use(logger('dev'))
app.use(errorhandler())
const {getPosts, addPost, updatePost, removePost, getComments, addComment, updateComment, removeComment} = require('./routes/')
// Posts
app.get('/posts', getPosts)
app.get('/posts/:postId', getPosts)
app.post('/posts', addPost)
app.put('/posts/:postId', updatePost)
app.delete('/posts/:postId', removePost)
// Comments
app.get('/posts/:postId/comments', getComments)
app.get('/posts/:postId/comments/:commentId', getComments)
app.post('/posts/:postId/comments', addComment)
app.put('/posts/:postId/comments/:commentId', updateComment)
app.delete('/posts/:postId/comments/:commentId', removeComment)
// Serve
app.listen(3000)