-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
34 lines (26 loc) · 926 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
const faker = require('faker');
const jsonServer = require('json-server');
const server = jsonServer.create();
server.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "http://localhost:3000");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS");
next()
});
const getArticles = () => {
const articles = [];
for (let id = 1; id < 51; id++) {
articles.push({
"id": id,
"title": faker.lorem.words(),
"description": faker.lorem.paragraphs(),
"isFavorite": false
})
}
return { "articles": articles }
};
const rewriter = jsonServer.rewriter({'/api/*': '/$1'});
const router = jsonServer.router(getArticles());
server.use(rewriter);
server.use(router);
module.exports = server;