123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- const jsonServer = require('json-server')
- const jsonDb = require('./static_db.json')
- const timezoneDb = require('./timezone.json')
- const server = jsonServer.create()
- const router = jsonServer.router()
- const middlewares = jsonServer.defaults()
- const GLOBAL_PORT = 3001
-
- function shuffle(array) {
- let currentIndex = array.length
- let randomIndex
-
-
- while (currentIndex !== 0) {
-
- randomIndex = Math.floor(Math.random() * currentIndex)
- currentIndex -= 1
-
-
- ;[array[randomIndex], array[currentIndex]] = [array[currentIndex], array[randomIndex]]
- }
-
- return array;
- }
-
- server.use(middlewares)
- server.use(jsonServer.bodyParser)
-
-
- server.get('/echo', (req, res) => res.jsonp('gg'))
- server.get('/login', (req, res) => res.jsonp(jsonDb.login))
- server.get('/user_logged', (req, res) => res.jsonp(jsonDb.user_logged))
- server.delete('/deletenodata', (req,res) => res.status(204).jsonp(''))
- server.patch('/user', (req, res) => res.jsonp({lang: 'fr'}))
-
-
-
-
-
-
- server.get('/lang', (req, res) => res.jsonp(jsonDb.lang))
-
- server.post('/sessions/login', (req, res) => {
- if (req.body.login !== '' && req.body.password !== '') return res.jsonp(jsonDb.user_logged)
- else return res.jsonp('error')
- })
-
- server.get('/app/config', (req, res) => res.jsonp(jsonDb.app_config))
-
- server.get('/sessions/whoami', (req, res) =>
-
- res.jsonp(jsonDb.user_logged)
- )
-
- server.get('/user/:id/workspace', (req, res) => res.jsonp(jsonDb.workspace_list))
-
- server.get('/workspace/:id', (req, res) => res.jsonp(
- {}
- ))
-
- server.get('/workspace/:idws/contents/', (req, res) => {
- console.log(req.query)
- if (req.query.parent_id !== undefined) {
- switch (req.query.parent_id) {
- case '3':
- return res.jsonp(jsonDb.folder_content_3)
- case '11':
- return res.jsonp(jsonDb.folder_content_11)
- }
- } else {
- return res.jsonp(
- Object.assign(
- {},
- jsonDb.workspace_detail,
- {
- content: shuffle(jsonDb.workspace_detail.content.map(
- c => Object.assign({}, c, {workspace_id: req.params.idws})
- ))
- },
- {id: req.params.idws}
- )
- )
- }
- })
-
- server.get('/user/:id/roles', (req, res) => res.jsonp(jsonDb.user_role))
-
- server.get('/timezone', (req, res) => res.jsonp(timezoneDb.timezone))
-
- server.get('/workspace/:idws/contents/:idc', (req, res) => {
- switch (req.params.idc) {
- case '1':
- case '5':
- return res.jsonp(jsonDb.content_data_pageHtml)
- case '2':
- return res.jsonp(jsonDb.content_data_thread)
- case '6':
- return res.jsonp({})
- }
- })
-
- server.put('/workspaces/:idws/html-documents/:idcts', (req, res) => {
- return res.jsonp(jsonDb.putHtmlDoc)
- })
-
- server.get('/workspace/:idws/contents/:idc/timeline', (req, res) => {
- switch (req.params.idc) {
- case '1':
- case '5':
- return res.jsonp(jsonDb.timeline)
- case '2':
- return res.jsonp([])
- case '6':
- return res.jsonp(jsonDb.timeline)
- }
- })
-
- server.post('/workspaces/:idws/contents', (req, res) => {
- console.log(req.body)
- return res.jsonp('gg')
- })
-
- server.use(router)
- server.listen(GLOBAL_PORT, () => {
- console.log('JSON Server is running on port : ' + GLOBAL_PORT)
- })
-
-
-
|