forms
This commit is contained in:
@@ -1,8 +1,53 @@
|
||||
const router = require('express').Router();
|
||||
const router2 = require('express').Router();
|
||||
const path = require('node:path')
|
||||
const fs = require('node:fs')
|
||||
|
||||
const timer = (time = 300) => (req, res, next) => setTimeout(next, time);
|
||||
let stubs = {
|
||||
users: 'success'
|
||||
}
|
||||
|
||||
router.use(timer());
|
||||
const timer = (time) => (req, res, next) => {
|
||||
setTimeout(next, time)
|
||||
}
|
||||
|
||||
timer.slow = timer(5000)
|
||||
timer.fast = timer(300)
|
||||
|
||||
// router.use(timer.fast)
|
||||
|
||||
router.post('/user-rate', (req, res) => {
|
||||
console.log(req.body)
|
||||
res.status(500).send({ ok: false })
|
||||
})
|
||||
|
||||
router.use('/admin', router2)
|
||||
|
||||
router.get('/users',
|
||||
(req, res, next) => {
|
||||
res.status(stubs.users.includes('error') ? 400 : 200).send(require(`../json/users/${stubs.users}.json`))
|
||||
})
|
||||
|
||||
router2.get('/', (req, res) => {
|
||||
res.send(`
|
||||
<h2>Users</h2>
|
||||
<ul>
|
||||
<li><button onclick="fetch('/api/admin/users/success')" style="background-color: ${stubs.users === 'success' ? 'green' : '#ccc'}">success</button></li>
|
||||
<li><button onclick="fetch('/api/admin/users/error')" style="background-color: ${stubs.users === 'error' ? 'green' : '#ccc'}">error</button></li>
|
||||
</ul>
|
||||
|
||||
<h2>Users</h2>
|
||||
<ul>
|
||||
<li><button onclick="fetch('/api/admin/users/success')" style="background-color: ${stubs.users === 'success' ? 'green' : '#ccc'}">success</button></li>
|
||||
<li><button onclick="fetch('/api/admin/users/error')" style="background-color: ${stubs.users === 'error' ? 'green' : '#ccc'}">error</button></li>
|
||||
</ul>
|
||||
`)
|
||||
})
|
||||
|
||||
router2.get('/:stubName/:value', (req, res) => {
|
||||
const { stubName, value } = req.params
|
||||
|
||||
stubs[stubName] = value
|
||||
})
|
||||
|
||||
module.exports = router;
|
||||
|
||||
6
stubs/json/users/empty.json
Normal file
6
stubs/json/users/empty.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"success": false,
|
||||
"body": {
|
||||
|
||||
}
|
||||
}
|
||||
41
stubs/json/users/success.json
Normal file
41
stubs/json/users/success.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"success": false,
|
||||
"body": {
|
||||
"some-user-id": {
|
||||
"id": "some-user-id",
|
||||
"name": "alexandr",
|
||||
"surname": null,
|
||||
"email": null,
|
||||
"rated": 3,
|
||||
"avatar": "https://www.gravatar.com/avatar/6529e885535ef67a3fad810ad71167c2c03f79480936e9b3a714731753cbb47e?d=robohash",
|
||||
"friends": [
|
||||
{
|
||||
"id": "2",
|
||||
"name": "not alexandr",
|
||||
"surname": null,
|
||||
"email": null,
|
||||
"rated": 2,
|
||||
"avatar": "https://www.gravatar.com/avatar/6e?d=robohash"
|
||||
}
|
||||
]
|
||||
},
|
||||
"2": {
|
||||
"id": "2",
|
||||
"name": "not alexandr",
|
||||
"surname": null,
|
||||
"email": null,
|
||||
"rated": 2,
|
||||
"avatar": "https://www.gravatar.com/avatar/6e?d=robohash",
|
||||
"friends": [
|
||||
{
|
||||
"id": "some-user-id",
|
||||
"name": "alexandr",
|
||||
"surname": null,
|
||||
"email": null,
|
||||
"rated": 3,
|
||||
"avatar": "https://www.gravatar.com/avatar/6529e885535ef67a3fad810ad71167c2c03f79480936e9b3a714731753cbb47e?d=robohash"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user