dchester / epilogue

Create flexible REST endpoints and controllers from Sequelize models in your Express app
846 stars 116 forks source link

Always return 'respond with a resource' #95

Closed husnulhamidiah closed 9 years ago

husnulhamidiah commented 9 years ago

I am using express generator. I put this code in bin/www. Here my code snapshot..

var app = require('../app'); // return app = express();
var models = require("../models"); // return sequelize initiation
var epilogue = require('epilogue');

...

epilogue.initialize({
  sequelize: models.Sequelize
});

var userResource = epilogue.resource({
  model: models.User,
  endpoints: ['/users', '/users/:id']
});

...

When I run the app. No error showing, but when I open http://localhost:3000/users it always return

respond with a resource

What I miss here. Or Did I make a mistake. Where should I put the initiation of epilogue to make it works.

mbroadst commented 9 years ago

Your code looks like and respond with a resource is not a string found in epilogue, so I'm wondering if you have some code in either of the two ... sections above that could interfere with epilogue's normal operation (In particular the ... before epilogue.initialize and epilogue.resource).

foxy0669 commented 9 years ago

I ran into the same problem. The express generator creates /users which is conflicting. In your /myapp.js file comment out the following:

    app.use('/', routes);
    app.use('/users', users);

I also commented out the catch 404 block below as I was getting a 404 error. (The 'respond with a resource' comes from ./routes/users.js)

mbroadst commented 9 years ago

ah sorry I totally missed that the express generator was being used, yes it's very likely you already have a top level definition for a route that epilogue is trying to generate. An easy solution for this is to pass a base to your call to epilogue.initialize. This way all of your epilogue endpoints will be prefixed with e.g. /api

@husnulhamidiah please let me know if this addresses your problem

husnulhamidiah commented 9 years ago

I'm not sure what i'm doing yesterday but it fix the problem.. But now it happens again..

I'll reverse my code and see what fix it.

mbroadst commented 9 years ago

@husnulhamidiah is this still an issue for you? I'd like to close it otherwise