Skip to content

read json before all actions so that can merge changes for json mannu… #795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "json-server",
"name": "json-server-visop",
"version": "0.13.0",
"description": "Serves JSON files through REST routes.",
"main": "./lib/server/index.js",
Expand All @@ -16,8 +16,8 @@
"fix": "npm run lint -- --fix",
"build": "babel src -d lib && webpack -p",
"toc": "markdown-toc -i README.md",
"prepublishOnly": "npm test && npm run build && pkg-ok",
"precommit": "npm test"
"prepublishOnly": "echo 124 ||npm test && npm run build && pkg-ok",
"precommit": "echo 124 ||npm test"
},
"dependencies": {
"body-parser": "^1.18.3",
Expand Down
5 changes: 3 additions & 2 deletions src/server/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const methodOverride = require('method-override')
const _ = require('lodash')
const lodashId = require('lodash-id')
const low = require('lowdb')
const fileAsync = require('lowdb/lib/storages/file-async')
// const fileAsync = require('lowdb/lib/storages/file-async')
const fileSync = require('lowdb/lib/storages/file-sync')
const bodyParser = require('../body-parser')
const validateData = require('./validate-data')
const plural = require('./plural')
Expand All @@ -25,7 +26,7 @@ module.exports = (source, opts = { foreignKeySuffix: 'Id' }) => {
db = low()
db.setState(source)
} else {
db = low(source, { storage: fileAsync })
db = low(source, { storage: fileSync })
}

validateData(db.getState())
Expand Down
19 changes: 8 additions & 11 deletions src/server/router/plural.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,14 @@ module.exports = (db, name, opts) => {

const w = write(db)

router
.route('/')
.get(list)
.post(create, w)

router
.route('/:id')
.get(show)
.put(update, w)
.patch(update, w)
.delete(destroy, w)
function r (req, res, next) {
db.read();
next();
};
router.route('/').get(r, list).post(r, create, w);

router.route('/:id').get(r, show).put(r, update, w).patch(r,update, w).delete(r, destroy, w);


return router
}
12 changes: 6 additions & 6 deletions src/server/router/singular.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ module.exports = (db, name) => {

const w = write(db)

router
.route('/')
.get(show)
.post(create, w)
.put(update, w)
.patch(update, w)
function r (req, res, next) {
db.read();
next();
};
router.route('/').get(r, show).post(r, create, w).put(r, update, w).patch(r, update, w);


return router
}