Compare commits
2 Commits
e6231f86b4
...
a3484f4525
Author | SHA1 | Date | |
---|---|---|---|
|
a3484f4525 | ||
|
876ef28221 |
@ -23,5 +23,6 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
config: {
|
config: {
|
||||||
"enterfront.api": "/api",
|
"enterfront.api": "/api",
|
||||||
|
// paste stand URL to config
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "enterfront",
|
"name": "enterfront",
|
||||||
"version": "0.2.3",
|
"version": "0.2.4",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "enterfront",
|
"name": "enterfront",
|
||||||
"version": "0.2.3",
|
"version": "0.2.4",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@brojs/cli": "^1.0.0",
|
"@brojs/cli": "^1.0.0",
|
||||||
"@brojs/create": "^1.0.0",
|
"@brojs/create": "^1.0.0",
|
||||||
|
@ -24,5 +24,5 @@
|
|||||||
"clean": "rimraf dist"
|
"clean": "rimraf dist"
|
||||||
},
|
},
|
||||||
"name": "enterfront",
|
"name": "enterfront",
|
||||||
"version": "0.2.3"
|
"version": "0.2.4"
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,14 @@ import { BrowserRouter } from 'react-router-dom';
|
|||||||
|
|
||||||
import { Dashboard } from './dashboard';
|
import { Dashboard } from './dashboard';
|
||||||
|
|
||||||
|
import { getConfigValue } from "@brojs/cli";
|
||||||
|
|
||||||
import './index.css'
|
import './index.css'
|
||||||
|
|
||||||
|
const BASE_API_URL = getConfigValue("enterfront.api");
|
||||||
|
|
||||||
|
// fetch(`${BASE_API_URL}/books/list`)
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
return(
|
return(
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
|
6
stubs/api/books/book-list.json
Normal file
6
stubs/api/books/book-list.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"content": {
|
||||||
|
|
||||||
|
},
|
||||||
|
"totalElement": 0
|
||||||
|
}
|
5
stubs/api/books/book.json
Normal file
5
stubs/api/books/book.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"id": "1",
|
||||||
|
"name": "Book name",
|
||||||
|
"description": "Interesting book description"
|
||||||
|
}
|
36
stubs/api/books/index.js
Normal file
36
stubs/api/books/index.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
const booksRouter = require('express').Router();
|
||||||
|
|
||||||
|
module.exports = booksRouter;
|
||||||
|
|
||||||
|
const books = []
|
||||||
|
|
||||||
|
booksRouter.get('/list', (req, res) => {
|
||||||
|
res.send(require('./book-list.json'))
|
||||||
|
})
|
||||||
|
|
||||||
|
booksRouter.post('/', (req, res) => {
|
||||||
|
// body() can be used because of dev server
|
||||||
|
console.log(req.body)
|
||||||
|
books.push({
|
||||||
|
name: req.body.name,
|
||||||
|
})
|
||||||
|
|
||||||
|
res.send({
|
||||||
|
status: 200
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
booksRouter.get('/:id', (req, res) => {
|
||||||
|
console.log(req.params);
|
||||||
|
|
||||||
|
res.send(require('./book.json'));
|
||||||
|
|
||||||
|
// res.status(404).send()
|
||||||
|
})
|
||||||
|
|
||||||
|
booksRouter.delete('/:id', (req, res) => {
|
||||||
|
res.status(201).send({
|
||||||
|
status: 'ok'
|
||||||
|
})
|
||||||
|
})
|
@ -1,3 +1,8 @@
|
|||||||
|
const booksRouter = require("./books");
|
||||||
const router = require('express').Router();
|
const router = require('express').Router();
|
||||||
|
const delay = require('./middlewares/delay');
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
||||||
|
// router.use(delay(300));
|
||||||
|
router.use('/books', delay, booksRouter);
|
||||||
|
5
stubs/api/middlewares/delay.js
Normal file
5
stubs/api/middlewares/delay.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
const delay = (ms = 1000) => (req, res, next) => {
|
||||||
|
setTimeout(next, ms)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = delay
|
Loading…
Reference in New Issue
Block a user