Giter Club home page Giter Club logo

koa-mongo-rest's People

Contributors

mgenev avatar t3chnoboy avatar tomaash 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

koa-mongo-rest's Issues

Error on running example

I ran the below code:

var createModel = require('koa-mongo-rest');

var schema = {
  schema: {
    email: String,
    name: String,
    password: String,
    address: String,
    zipcode: Number,
    lists: Array
  },
  collectionName: 'user'
};


var koa = require('koa');
var router = require('koa-router');

var mongoUrl = '127.0.0.1:27017'
var app = koa();
app.use(router(app));
var model = app.model = createModel(schema, mongoUrl);
model.generateApi(app);

app.listen(process.env.PORT || 5000);

and got error:

  return pluralize(name.toLowerCase());
                        ^
TypeError: Cannot call method 'toLowerCase' of undefined
    at exports.toCollectionName (/Users/XXXX/node_modules/mongoose/lib/utils.js:28:25)
    at Mongoose.model (/Users/XXXX/node_modules/mongoose/lib/index.js:361:46)
    at model (/Users/XXXX/node_modules/koa-mongo-rest/lib/model.js:11:19)
    at api (/Users/XXXX/node_modules/koa-mongo-rest/lib/index.js:10:11)
    at Object.<anonymous> (/Users/XXXX/Downloads/koa-mongo-rest-master/example/app.js:22:9)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:349:32)
    at Function.Module._load (module.js:305:12)
    at Function.Module.runMain (module.js:490:10)

I also ran the example in koa-mongo-rest/example, it did lanuch successfully, but when I changed createModel = require('../lib/index'); to createModel = require('koa-mongo-rest');, the same error occurred.

Unable to run example. Gives error - app.use() requires a generator function

I am running the example, with a simple modification in require koa-mongo-rest

koa = require('koa');
router = require('koa-router');
generateApi = require('koa-mongo-rest');

mongoUrl = '127.0.0.1:27017';
mongoose = require('mongoose');
mongoose.connect(mongoUrl);

schema = new mongoose.Schema({
  email: String,
  name: String,
  password: String,
  address: String,
  zipcode: Number,
  lists: Array
});

app = koa();
app.use(router(app));

model = mongoose.model('user', schema);
generateApi(app, model, '/api');

app.listen(process.env.PORT || 5000);

It gives me this error:
C:\del\mongotest>npm start

[email protected] start C:\del\mongotest
node --harmony app.js

assert.js:86
throw new assert.AssertionError({
^
AssertionError: app.use() requires a generator function
at Application.app.use (C:\del\mongotest\node_modules\koa\lib\application.js:100:5)
at Object. (C:\del\mongotest\app.js:19:5)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "start"
npm ERR! node v0.12.5
npm ERR! npm v2.11.2
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: node --harmony app.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script 'node --harmony app.js'.
npm ERR! This is most likely a problem with the mongotest package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node --harmony app.js
npm ERR! You can get their info via:
npm ERR! npm owner ls mongotest
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! C:\del\mongotest\npm-debug.log

Docs Request: How can we add access control to various routes?

I have some idea about how to add access control with koa and koa-mongo-rest. It would be nice to see it documented though since that may be a main point of concern before adopting this system.

Maybe something like:

apiAuthorizationMap = {
    '/api/users/:id': function* () {
            // this.session......
            yield true;
    }
};

app.use(function* (next) {
    // this.route doesn't quite work, but let's hand wave for now.
    if (this.method === 'GET' || apiAuthorizationMap[this.route].apply(this)) {
        yield next;
    } else {
         this.throw('Unauthorized', 401);
    }
});

Do you guys have a better way?

does not work with koa logger

Other requests to the application are logged, but the once handled by this module do not.

Great work by the way :)

incompatible with koabodyparser

when I add app.use(bodyParser) all the methods in koa-mongo-rest which look for the body start failing silently and the request is left hanging.

I'm not sure how to deal with that yet, so I'm opening for discussion.

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.