Giter Site home page Giter Site logo

keystone-rest's People

Contributors

creynders avatar danielpquinn avatar dtrierweiler19 avatar jcmandersson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

keystone-rest's Issues

How to use middleware.requireUser?

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?

Security & Pagination

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:

  • I haven't put anything in production yet with Keystone.js but the eventual concern would of course be authentication and authorization. Can keystone-rest use authentication?
  • Being able to do server side pagination out of the box would be awesome. Does keystone-rest do that?

support for LocalFile and file upload in general

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 ?

Cannot read property 'schema' of undefined

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);

support for LocalFile and file upload in general

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 ?

TypeError: Object #<IncomingMessage> has no method 'flash'

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.