Skip to content
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

Fixing createRest method #3

Open
wants to merge 5 commits into
base: master
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: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ This extension for Keystone is intended to create a REST API very easy. Also is

// Make sure keystone is initialized and started before
// calling createRest

keystone.init(config);
keystone.start();

// Add routes with Keystone
keystoneRestApi.createRest(keystone, {
apiRoot: '/api/v1/'
apiRoot: '/api/'
});

keystone.start();

// Create Documentation and write it to a file
fs.writeFileSync('api.md', keystoneRestApi.apiDocs(), 'UTF-8');
Expand Down
15 changes: 10 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,10 @@ function KeystoneRest() {
if (err) {
return _sendError(err, req, res, next);
}

var query = Model.find(criteria).skip(req.query.skip)
.limit(req.query.limit)
var limit = req.query.limit ? Number.parseInt(req.query.limit) : undefined;
var skip = req.query.skip ? Number.parseInt(req.query.skip) : undefined;
var query = Model.find(criteria).skip(skip)
.limit(limit)
.sort(req.query.sort)
.select(querySelect || selected);

Expand Down Expand Up @@ -808,8 +809,12 @@ function KeystoneRest() {
// Get and register the models
_registerRestModels(keystone);

_.each(self.routes, function (route) {
keystone.app[route.method](route.route, route.middleware, route.handler);
const setCurrentRoutes = keystone.get('routes')
keystone.set('routes', app => {
setCurrentRoutes(app)
_.each(self.routes, function (route) {
app[route.method](route.route, route.middleware, route.handler);
});
});
};

Expand Down