-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
37 lines (30 loc) · 1.36 KB
/
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
35
36
37
const express = require('express');
const db = require('./db');
const logger = require('morgan')
const bodyParser = require('body-parser')
const app = express();
const cors = require('cors')
const methodOverride = require('method-override')
const PORT = process.env.PORT || 3001;
const usersController = require('./controllers/usersController');
const postsController = require('./controllers/postsController');
const commentsController = require('./controllers/commentsController');
app.use(methodOverride('_method'))
app.use(cors())
app.use(logger('dev'))
app.use(bodyParser.json())
app.use(express.urlencoded( { extended: true}))
app.get('/users', usersController.getAllUsers)
app.post('/users', usersController.createUser)
app.delete('/users/:id', usersController.deleteUser)
app.put('/users/:id', usersController.updateUser)
app.get('/posts', postsController.getAllPosts)
app.post('/posts', postsController.createPost)
app.delete('/posts/:id', postsController.deletePost)
app.put('/posts/:id', postsController.updatePost)
app.get('/comments', commentsController.getAllComments)
app.post('/comments', commentsController.createComment)
app.delete('/comments/:id', commentsController.deleteComment)
app.put('/comments/:id', commentsController.updateComment)
app.get('/comments', commentsController.getAllComments)
app.listen(PORT, () => console.log(`Listening on port: ${PORT}`))