rethinkdb / horizon

Horizon is a realtime, open-source backend for JavaScript apps.
MIT License
6.78k stars 351 forks source link

Basic example app not connecting #854

Open jonlambert opened 7 years ago

jonlambert commented 7 years ago

When creating a new app via hz init, the client fails (silently) to connect.

Steps to reproduce:

$ hz init hz-test && cd hz-test
$ hz schema apply .hz/schema.toml
$ hz serve --secure=no --serve-static

Browse to the Horizon server. The /horizon/horizon.js client script is loaded successfully, however the h1 tag is never populated with the success message. onReady is never called, and any attempts to perform actions on the database are unsuccessful.

No errors in the client console, nor in the server logs.

Operating System: macOS 10.12 Server version: 2.0.0 Client version: 2.0.0 Node version: 6.9.1

sdwlig commented 7 years ago

I was having the same problem. Things worked well for a while, then stopped suddenly. It may be your auth token, anonymous or otherwise. If so, this cures it. This is related to total lack of error reporting for certain connection & auth issues. Horizon.clearAuthTokens();

jonlambert commented 7 years ago

Thanks for your suggestion @sdwlig, but no such luck. I've tried using the above method both in the console and before calling .connect(). This is unbelievably frustrating.

sdwlig commented 7 years ago

We need full trace and logging on both the client and server about what's going on, which steps fail, etc. I'll work on that if I can get to it.

Also make sure that your schema allows operations for your connection. This is my wide-open starting point, which got me past another sticking point earlier: .hz/schema.toml: [groups.unauthenticated.rules.read] template = "collection('messages').anyRead()"

[groups.unauthenticated.rules.write] template = "collection('messages').anyWrite()"

[groups.authenticated.rules.read] template = "collection('messages').anyRead()"

[groups.authenticated.rules.write] template = "collection('messages').anyWrite()"

[groups.admin] [groups.admin.rules.carte_blanche] template = "any()"

jonlambert commented 7 years ago

Thanks for your suggestion, but unfortunately that hasn't fixed it! Is this a problem you're also experiencing? Or perhaps an issue with my environment?

sdwlig commented 7 years ago

I was just having the expired token problem. The permissions issue was a few days ago. I'm OK now, but only because I turned off all security, etc. The biggest problem I know that I have is using the Horizon integrated mode with Node + Express while also being able to service Express routes (get / etc.) at the same time. (And really also my own websocket server routes.) The way that Horizon creates it's own servers seems to interfere with all of the Express routes. Not much good to embed Horizon if I can't find a way to run my own code next to it. Again, missing a complete enough example to be useful. I'll get back to it soon.

Another thing I could try is to check out Horizon from github, use the cd test; ./setupDev.sh method of activating that. This is actually what I use, and I've merged in 2 patches that were not accepted to get CORS support and allow redirecting after auth. The latter was rejected as being a security risk, but during development I don't care: I need to be able to server app HTML/code separately from the API/DB server. I may be able to make my hacked Horizon public soon.