danielpquinn / keystone-rest Goto Github PK
View Code? Open in Web Editor NEWProvides a RESTful interface to keystone lists.
Provides a RESTful interface to keystone lists.
Using Restangular in my frontend and would love to see the PATCH method implemented in keystone-rest
I was just wondering if there is any recommended way to protect api routes?
req.user is undefined in registerRoutes so can't do
app[route.method](route.route, middleware.requireUser, route.handler);
and i don't see keystone's log for routes added this way
so i do following instead of keystoneRest.registerRoutes(...);
keystone.apiRoutes = keystone.apiRoutes || [];
keystone.apiRoutes.push(keystoneRest);
and then in routes/index.js when req.user is defined
keystone.apiRoutes.forEach(function(keystoneRest) {
keystoneRest.registerRoutes(keystone.app, middleware.requireUser);
});
this obviously need a change in reqisterRoutes function
this.registerRoutes = function(app, requireUser) {
_.each(this.routes, function(route) {
if(requireUser){
app[route.method](route.route, requireUser, route.handler);
}else{
app[route.method](route.route, route.handler);
}
});
};
So is there any other/better way to achieve this or am i missing something?
Hi!
I think this package is really really useful. Keystone.js together with this is a very nice system for rapid prototyping. There's two things I have a question about though:
Is there a way to do it ?
I have models with LocalFile and i would like the client to be able to upload / get them. Not sure what's the best practice for this. Can we establish one and add it to the tests ?
This is the error I get:
/keystone-rest/index.js:433
var selected = _getSelected(keystoneList.model.schema);
^
TypeError: Cannot read property 'schema' of undefined
Here is my implementation:
/* globals app */
var keystone = require('keystone'),
Types = keystone.Field.Types,
keystoneRest = require('keystone-rest');
/**
* Enquiry Model
* =============
*/
var Enquiry = new keystone.List('Enquiry', {
nocreate: true,
noedit: true
});
Enquiry.add({
name: { type: Types.Name, required: true },
email: { type: Types.Email, required: true },
phone: { type: String },
enquiryType: { type: Types.Select, options: [
{ value: "message", label: "Just leaving a message" },
{ value: "question", label: "I've got a question" },
{ value: "other", label: "Something else..." }
] },
message: { type: Types.Markdown, required: true },
createdAt: { type: Date, default: Date.now }
});
Enquiry.defaultSort = '-createdAt';
Enquiry.defaultColumns = 'name, email, enquiryType, createdAt';
// Expose User model via REST api
keystoneRest.addRoutes(Enquiry, 'get');
Enquiry.register();
// Add routes to app
keystoneRest.registerRoutes(app);
Is there a way to do it ?
I have models with LocalFile and i would like the client to be able to upload / get them. Not sure what's the best practice for this. Can we establish one and add it to the tests ?
When using KeystoneRest as the documentation specify, getting the following error:
undefined_method Error thrown for request: /keystone/signin
TypeError: Object # has no method 'flash'
at [object Object].Keystone.render (//keystone-demo/node_modules/keystone/index.js:265:17)
at renderView (//keystone-demo/node_modules/keystone/routes/views/signin.js:7:12)
at module.exports (//keystone-demo/node_modules/keystone/routes/views/signin.js:50:3)
at callbacks (//keystone-demo/node_modules/keystone/node_modules/express/lib/router/index.js:164:37)
at param (//keystone-demo/node_modules/keystone/node_modules/express/lib/router/index.js:138:11)
at pass (//keystone-demo/node_modules/keystone/node_modules/express/lib/router/index.js:145:5)
at Router._dispatch (//keystone-demo/node_modules/keystone/node_modules/express/lib/router/index.js:173:5)
at Object.router (//keystone-demo/node_modules/keystone/node_modules/express/lib/router/index.js:33:10)
at next (//keystone-demo/node_modules/keystone/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.expressInit as handle
at next (//keystone-demo/node_modules/keystone/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.query as handle
at next (//keystone-demo/node_modules/keystone/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Function.app.handle (//keystone-demo/node_modules/keystone/node_modules/express/node_modules/connect/lib/proto.js:198:3)
at Server.app (//keystone-demo/node_modules/keystone/node_modules/express/node_modules/connect/lib/connect.js:65:37)
at Server.EventEmitter.emit (events.js:98:17)
at HTTPParser.parser.onIncoming (http.js:2076:12)
at HTTPParser.parserOnHeadersComplete as onHeadersComplete
at Socket.socket.ondata (http.js:1966:22)
at TCP.onread (net.js:525:27)
undefined_method Error thrown for request: /keystone/signin?from=/keystone/styles/error.css
TypeError: Object # has no method 'flash'
at [object Object].Keystone.render (//keystone-demo/node_modules/keystone/index.js:265:17)
at renderView (//keystone-demo/node_modules/keystone/routes/views/signin.js:7:12)
at module.exports (//keystone-demo/node_modules/keystone/routes/views/signin.js:50:3)
at callbacks (//keystone-demo/node_modules/keystone/node_modules/express/lib/router/index.js:164:37)
at param (//keystone-demo/node_modules/keystone/node_modules/express/lib/router/index.js:138:11)
at pass (//keystone-demo/node_modules/keystone/node_modules/express/lib/router/index.js:145:5)
at Router._dispatch (//keystone-demo/node_modules/keystone/node_modules/express/lib/router/index.js:173:5)
at Object.router (//keystone-demo/node_modules/keystone/node_modules/express/lib/router/index.js:33:10)
at next (//keystone-demo/node_modules/keystone/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.expressInit as handle
at next (//keystone-demo/node_modules/keystone/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Object.query as handle
at next (//keystone-demo/node_modules/keystone/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Function.app.handle (//keystone-demo/node_modules/keystone/node_modules/express/node_modules/connect/lib/proto.js:198:3)
at Server.app (//keystone-demo/node_modules/keystone/node_modules/express/node_modules/connect/lib/connect.js:65:37)
at Server.EventEmitter.emit (events.js:98:17)
at HTTPParser.parser.onIncoming (http.js:2076:12)
at HTTPParser.parserOnHeadersComplete as onHeadersComplete
at Socket.socket.ondata (http.js:1966:22)
at TCP.onread (net.js:525:27)
Fixed the error by registering the routes only after app start, as so:
// Start web server
keystone.start();
// Register api routes
keystoneRest.registerRoutes(keystone.app);
Am I using the API correctly?
Can I make it work as the documentation specify?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.