Roughing out the demo app

This commit is contained in:
Nate Taylor
2019-10-23 07:41:03 -05:00
parent 5bc58a2d40
commit 94be06d3c4
2841 changed files with 274065 additions and 2 deletions

29
node_modules/json-server/lib/server/router/nested.js generated vendored Normal file
View File

@@ -0,0 +1,29 @@
"use strict";
const express = require('express');
const pluralize = require('pluralize');
const delay = require('./delay');
module.exports = opts => {
const router = express.Router();
router.use(delay); // Rewrite URL (/:resource/:id/:nested -> /:nested) and request query
function get(req, res, next) {
const prop = pluralize.singular(req.params.resource);
req.query[`${prop}${opts.foreignKeySuffix}`] = req.params.id;
req.url = `/${req.params.nested}`;
next();
} // Rewrite URL (/:resource/:id/:nested -> /:nested) and request body
function post(req, res, next) {
const prop = pluralize.singular(req.params.resource);
req.body[`${prop}${opts.foreignKeySuffix}`] = req.params.id;
req.url = `/${req.params.nested}`;
next();
}
return router.get('/:resource/:id/:nested', get).post('/:resource/:id/:nested', post);
};