forked from danielstern/express-react-fullstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.mock.js
More file actions
42 lines (34 loc) · 881 Bytes
/
server.mock.js
File metadata and controls
42 lines (34 loc) · 881 Bytes
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
38
39
40
41
42
/**
* This mock server does not communicate with the DB and therefore does not provide data persistence.
*/
import express from 'express';
import cors from 'cors';
import bodyParser from 'body-parser';
import { defaultState } from './defaultState';
let port = 7777;
let app = express();
const authorizationTokens = [];
app.use(
cors(),
bodyParser.urlencoded({extended:true}),
bodyParser.json()
);
app.get('/user/:id',(req,res)=>{
let user = defaultState.users.find(user=>user.id === req.params.id);
if (!user) {
res.status(500).send();
} else {
res.json(user);
}
});
app.post(`/task/new`,(req,res)=>{
let { task } = req.body;
res.status(200).send();
});
app.post(`/task/update`,(req,res)=>{
let { task } = req.body;
res.status(200).send();
});
app.post(`comment/new`,(req,res)=>{
res.status(200).send();
});