kahmali / meteor-restivus

REST APIs for the Best of Us! - A Meteor 0.9+ package for building REST APIs https://atmospherejs.com/nimble/restivus
MIT License
544 stars 116 forks source link

Restivus with todos example app #181

Closed ajholyoake closed 8 years ago

ajholyoake commented 8 years ago

I am trying to add restivus to the todos example app. However, it looks as thought restivus is calling iron-router (which I understand is no longer a dependency of restivus.

The following error message is produced:

Error: Route constructor first parameter must be a Router
    at Object.Utils.assert (packages/iron_router/packages/iron_router.js:30:1)
    at new Route (packages/iron_router/packages/iron_router.js:320:1)
    at Restivus.Restivus.addRoute (packages/nimble_restivus/packages/nimble_restivus.js:562:1)
    at Restivus.Restivus._initAuth (packages/nimble_restivus/packages/nimble_restivus.js:922:1)
    at new Restivus (packages/nimble_restivus/packages/nimble_restivus.js:538:1)
    at lib/collections.js:19:1
    at lib/collections.js:23:1
    at C:\Users\aholyoake\WeatherStation\.meteor\local\build\programs\server\boot.js:242:10
    at Function._.each._.forEach (C:\Users\aholyoake\AppData\Local\.meteor\packages\meteor-tool\1.1.10\mt-os.windows.x86_32\
nderscore\underscore.js:79:11)
    at Array.forEach (native)

The code I have used is

Todos = new Mongo.Collection('todos');
if(Meteor.isServer)
{
  Api = new Restivus({useDefaultAuth:true, prettyJson:true});
 Api.addCollection(Todos);
}

(tried in lib/collections.js and server/publish.js separately)

As you can see this is on Windows, which may be a complication!

I'm running the latest meteor and have removed the pinned-version iron-router from the packages file.

Restivus was installed with meteor add nimble:restivus

Any ideas?

ajholyoake commented 8 years ago

Here is the output of meteor list

accounts-password     1.1.4  Password support for accounts
blaze-html-templates  1.0.1  Compile HTML templates into reactive UI with Meteor Blaze
check                 1.1.0  Check whether a value matches a pattern
insecure              1.0.4  (For prototyping only) Allow all database writes from the client
iron:router           0.9.4* Routing specifically designed for Meteor
jquery                1.11.4  Manipulate the DOM using CSS selectors
less                  2.5.1  Leaner CSS language
meteor-base           1.0.1  Packages that every Meteor app needs
mobile-experience     1.0.1  Packages for a great mobile user experience
mongo                 1.1.3  Adaptor for using MongoDB and Minimongo over DDP
nimble:restivus       0.8.4  Create authenticated REST APIs in Meteor 0.9+ via HTTP/HTTPS. Setup CRUD endpoints for Collections.
session               1.1.1  Session variable
standard-minifiers    1.0.2  Standard minifiers used with Meteor apps by default.
tracker               1.0.9  Dependency tracker to allow reactive callbacks
kahmali commented 8 years ago

My best guess is that Restivus' Route object is being overwritten by Iron Router. I believe this is the same issue as described in #170. I was waiting on a PR from the user that reported it because I don't really have the time to work on Restivus nowadays. I'll make an exception since this is a really annoying bug (and I already have it fixed locally as you'll read in the other thread I linked).

I'm gonna push up a fix onto a new branch here, but I'll need you to test it locally, if you don't mind, to see if that actually resolves your problem. I don't want to have to publish a new version just to find out this didn't fix your issue. Gimme a sec.

kahmali commented 8 years ago

Alright. I just submitted PR #182 with a potential fix. Can you test it out locally for me? It's on the route-namespace branch.

ajholyoake commented 8 years ago

Cheers for the speedy response - I'm getting the same error as the travis CI build when installed locally

error: File not found: lib/package-scope-variables.js

kahmali commented 8 years ago

Whoops. Left an old untracked file in there. Sorry about that. I had the file locally so everything ran okay for me. This is why we use CI and check with others :) Let me fix that up and push again. One sec.

kahmali commented 8 years ago

Alright. Try it again. Just grab the latest on that branch.

ajholyoake commented 8 years ago

It's gone one step along the line it seems - I've got something very close to the original error message. However, it's bombing out during the addCollection method, rather than during the call to new Restivus

Just to clarify what I've done - I have created a packages directory in my project, downloaded the zip for the route-namespace branch (as I have a corporate firewall to deal with), run meteor remove nimble:restivus and then immediately afterwards meteor add nimble:restivus.

Here's the current message

C:\Users\aholyoake\AppData\Local\.meteor\packages\meteor-tool\1.1.10\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:245
                        throw(ex);
                              ^
Error: Route constructor first parameter must be a Router
    at Object.Utils.assert (packages/iron_router/packages/iron_router.js:30:1)
    at new Route (packages/iron_router/packages/iron_router.js:320:1)
    at Restivus.Restivus.addRoute (packages/nimble_restivus/packages/nimble_restivus.js:562:1)
    at Restivus.Restivus.addCollection (packages/nimble_restivus/packages/nimble_restivus.js:616:1)
    at lib/collections.js:9:1
    at lib/collections.js:22:1
    at C:\Users\aholyoake\WeatherStation\.meteor\local\build\programs\server\boot.js:242:10
    at Array.forEach (native)
    at Function._.each._.forEach (C:\Users\aholyoake\AppData\Local\.meteor\packages\meteor-tool\1.1.10\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\underscore\underscore.js:79:11)
    at C:\Users\aholyoake\WeatherStation\.meteor\local\build\programs\server\boot.js:137:5
Exited with code: 8
Your application is crashing. Waiting for file change.
ajholyoake commented 8 years ago

Hi Kahmali,

I've done a meteor reset and that cleared my cache out. I'm getting data out of the endpoints now, so it looks good to me!

Cheers for the help!

kahmali commented 8 years ago

Phew! I was about to give up on you :P Iron Router is such a headache (just search "iron router" in the Restivus issues and you'll see what I mean). I strongly recommend that you check out some tutorials that use Flow Router. I think most folks would agree that it's the best router for Meteor. We use it extensively in NimbleNotes and it's never been an obstacle to development. I wish I could say the same for Iron Router.

I'll go ahead and bump the version and publish that. Thanks for reporting the issue and testing that out for me! Greatly appreciated! I'll let you know once it's published.

kahmali commented 8 years ago

I just published v0.8.5 with this fix. Thanks so much for your help!