KSP-SpaceDock / OpenDock

Old Experimantal Implementation (not finished, please ignore)
MIT License
3 stars 3 forks source link

backend-url setting gets corrupted somehow #4

Closed HebaruSan closed 6 years ago

HebaruSan commented 6 years ago

Description (What went wrong?):

OpenDock loads to a large loading animation and stays that way:

image

If I open the dev tools and delete the div containing that graphic, the page content is there but (unsurprisingly) not initialized:

image

Reproduction Steps (What did you do?):

Set these in config.php across different tests:

        'backend-url' => 'http://127.0.0.1:5000/',
        'backend-url' => 'https://127.0.0.1:5000/',

Expected Behavior (What do you think should have happened instead?):

Presumably the loading screen should only be visible for a few seconds or less.

Environment (OS/Browser/Plugins/etc):

Extra Information (Screenshots/Error Messages/Javascript Console Output):

Several errors show up in the browser console with invalid URLs that are apparent perversions of the configured backend-url. It looks like the first colon is spliced out, and then http:// is added to the beginning:

With http://127.0.0.1:5000/:

image

With https://127.0.0.1:5000/:

image

Maybe the setting isn't actually supposed to be a URL?

Xinayder commented 6 years ago

You don't need the protocol in the backend-url config field.

HebaruSan commented 6 years ago

Removing the protocol gives me this:

        'backend-url' => '127.0.0.1:5000/',

image

I assume the double slashes are the culprit. I'd suggest renaming this setting to backend-host since it does not work with URLs.

StollD commented 6 years ago

OpenDock used to prefix the value from backend-url with // automatically (so it should use the same protocol the site itself used).

I changed it to detect if it is prefixed with http:// or https:// and if thats the case, use the protocol specified by the user, otherwise use the one the site uses.

https://github.com/KSP-SpaceDock/OpenDock/commit/999fdce402ddf1afa3f7d93016ac696ade726449

HebaruSan commented 6 years ago

That looks like a fix to me. Thanks!

HebaruSan commented 6 years ago

Is it possible to bootstrap from an empty database? My backend seems to be returning nothing for these four calls, and I was expecting that I could start from nothing, register the first user, upload the first mod, etc. However, an exception is thrown because browse.data is undefined:

image

The code where this exception is thrown:

https://github.com/KSP-SpaceDock/OpenDock/blob/77b61b5140d45c561ad90dc81899cf856962f36a/scripts/index.js#L13-L19

I can't tell whether the front end should be more prepared for this possibility, or if the backend should be returning something.

Xinayder commented 6 years ago

If I recall correctly, you need to install some plugins, more specifically adapter, search and transformers.

StollD commented 6 years ago

The backend has it's own command for that, it can setup the database with the data that is required to use it.

usage: sdb setup [-dummy=true|false]

The setup subcommand will add an administrator account, a normal user,
publisher, game, game admin and some dummy mods to the database.

If you set the dummy flag to false, only an admin account will be added.

This is mainly used to populate internal data (like the various permissions).

Also, the request fails because you try to browse the mods for a game with the gameshort KSP, since your database is empty, the game isn't found and the backend returns a 404 error message. The dummy data that is added by sdb setup uses kerbal-space-program as the short name (the same that SpaceDock uses).

OpenDock currently requires that one game is added to the database, #2 tries to change that, but I didn't have the time to finish it properly.

HebaruSan commented 6 years ago

But that's a long name. :(

Hmm, I did run sdb setup, both before and after installing the plugins. Does it run differently with plugins installed?

StollD commented 6 years ago

It shouldn't. Maybe it is simply the KSP vs. kerbal-space-program issue.

HebaruSan commented 6 years ago

Similar result with kerbal-space-program:

image

HebaruSan commented 6 years ago

Trying http://127.0.0.1:5000/api/users/current in a browser says:

{"codes":[1035],"error":true,"reasons":["You need to be logged in to access this page"]}

... which seems like a reasonable enough response. It's true that I'm not logged in, and it makes sense to hide certain info from anonymous users.

StollD commented 6 years ago

OpenDock expects that response and deals with it. However, since the browse stuff is what is failing (and it isn't limited to logged in users), could you post the response of /api/games please?

HebaruSan commented 6 years ago

That returns the empty string, or as my browser puts it:

This page isn’t working 127.0.0.1 didn’t send any data. ERR_EMPTY_RESPONSE

StollD commented 6 years ago

Thats really confusing, it should at least return an empty array.

My last idea would be to delete and recreate the database completely, but I am unsure how much that would actually help

Xinayder commented 6 years ago

What about your database, is it populated?

StollD commented 6 years ago

He said he ran sdb setup two times, so I would assume it is.

HebaruSan commented 6 years ago

Yeah, if there's some way of independently verifying that sdb setup worked, I'll happily try it, but for now I'm assuming it worked.

StollD commented 6 years ago

Well, you could open the database and check if there is something inside of the tables. Or you could export it to an .sql file and upload it, so we can check.

HebaruSan commented 6 years ago

OK, here's some psql command line. I'll prune the tables that don't seem related...

SELECT * FROM pg_catalog.pg_tables ORDER BY tableowner;

     schemaname     |        tablename        | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity 
--------------------+-------------------------+------------+------------+------------+----------+-------------+-------------
 public             | abilities               | spacedock  |            | t          | f        | f           | f
 public             | download_events         | spacedock  |            | t          | f        | f           | f
 public             | follow_events           | spacedock  |            | t          | f        | f           | f
 public             | referral_events         | spacedock  |            | t          | f        | f           | f
 public             | featureds               | spacedock  |            | t          | f        | f           | f
 public             | games                   | spacedock  |            | t          | f        | f           | f
 public             | shared_authors          | spacedock  |            | t          | f        | f           | f
 public             | tokens                  | spacedock  |            | t          | f        | f           | f
 public             | game_versions           | spacedock  |            | t          | f        | f           | f
 public             | mod_followers           | spacedock  |            | t          | f        | f           | f
 public             | role_abilities          | spacedock  |            | t          | f        | f           | f
 public             | mods                    | spacedock  |            | t          | f        | f           | f
 public             | mod_lists               | spacedock  |            | t          | f        | f           | f
 public             | mod_list_items          | spacedock  |            | t          | f        | f           | f
 public             | mod_versions            | spacedock  |            | t          | f        | f           | f
 public             | publishers              | spacedock  |            | t          | f        | f           | f
 public             | ratings                 | spacedock  |            | t          | f        | f           | f
 public             | role_users              | spacedock  |            | t          | f        | f           | f
 public             | roles                   | spacedock  |            | t          | f        | f           | f
 public             | users                   | spacedock  |            | t          | f        | f           | f
spacedockbackend=> select * from games;
 id |          created_at           |          updated_at           | deleted_at | meta |         name         | active | altname | rating |          releasedate          |        short         | publisher_id | description | short_description 
----+-------------------------------+-------------------------------+------------+------+----------------------+--------+---------+--------+-------------------------------+----------------------+--------------+-------------+-------------------
  2 | 2018-02-15 21:55:44.274209-06 | 2018-02-15 21:55:44.275501-06 |            | {}   | Factorio             | t      |         |      0 | 2018-02-15 21:55:44.274091-06 | factorio             |            2 |             | 
  1 | 2018-02-15 21:55:44.268473-06 | 2018-02-15 21:56:03.887121-06 |            | {}   | Kerbal Space Program | t      |         |      0 | 2018-02-15 21:55:44.268388-06 | kerbal-space-program |            1 |             | 
(2 rows)
Xinayder commented 6 years ago

Were you running the backend when you queried /api/games?

EDIT: if it doesn't work, try adding a trailing slash, e.g. /api/games/

HebaruSan commented 6 years ago

Yup. If I wasn't, nothing would have been listening on that port, so it would have said "The site can't be reached"/ERR_CONNECTION_REFUSED instead.

image

Xinayder commented 6 years ago

Can you screenshot the error that is being thrown by sdb?

HebaruSan commented 6 years ago

sdb isn't raising errors. The terminal in that screenshot shows sdb while the page is refreshed.

StollD commented 6 years ago

Thats a go stacktrace, so something is going terribly wrong there. So not really a user error, but an exception thrown by the code.

Normally it shouldn't show those :D

HebaruSan commented 6 years ago

Aha! I guess that "redis" thing is required after all, going by the port number?

2018/02/16 15:51:40 http: panic serving 127.0.0.1:58344: dial tcp [::1]:6379: getsockopt: connection refused
goroutine 1108 [running]:

Sorry, I didn't know what that was. I'll go look it up...

StollD commented 6 years ago

Change store-type: "redis" to store-type: "memory" in your config.yml, then it shouldn't try to use redis.

HebaruSan commented 6 years ago

That was definitely it!!

{"count":2,"data":[{"active":true,"altname":"","created":"2018-02-15T21:55:44.274209-06:00","description":"","id":2,"meta":{},"name":"Factorio","publisher":2,"rating":0,"releasedate":"2018-02-15T21:55:44.274091-06:00","short":"factorio","short_description":"","updated":"2018-02-15T21:55:44.275501-06:00"},{"active":true,"altname":"","created":"2018-02-15T21:55:44.268473-06:00","description":"","id":1,"meta":{},"name":"Kerbal Space Program","publisher":1,"rating":0,"releasedate":"2018-02-15T21:55:44.268388-06:00","short":"kerbal-space-program","short_description":"","updated":"2018-02-15T21:56:03.887121-06:00"}],"error":false}

image

HebaruSan commented 6 years ago

And after installing redis-server, using redis seems to work as well.

If it's OK with you, I'd like to use my notes from this to make the README more idiot-proof. I think I hit most of the stumbling blocks that a new person is likely to encounter.

StollD commented 6 years ago

I would love that! It's always terribly hard to write a README if you wrote the program too, because you don't know which things might be obvious, and which are hard to spot.