muesli / beehive

A flexible event/agent & automation system with lots of bees 🐝
GNU Affero General Public License v3.0
6.25k stars 318 forks source link

Bug: web UI trying to fetch localhost instead real address #350

Open quenbyako opened 3 years ago

quenbyako commented 3 years ago

Soooooo strange to say it, but:

i reproduced issue #156, which said that webserver is broken (not a webserver, actualy, but web ui)

What happens:

I installed docker container on my dedicated server with my domain (somecooldomain.com, i don't want to show it), BUT!

js code is trying to get another js script from localhost! Just, you know, forcely get, this is a part of error log:


The adapter operation was aborted:
t@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:11:15854
i@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:30:11457
r@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:30:11681
l@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:30:15814
ajax/</c.error@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:30:21485
l@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:5:26983
fireWith@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:5:27749
n@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:6:31413
r/<@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:7:4257
EventHandlerNonNull*send@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:7:4484
ajax@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:7:2126
_ajaxRequest@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:30:21618
ajax/<@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:30:21527
T@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:23:13428
j@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:23:15058
ajax@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:30:21303
findAll@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:30:17227
c@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:30:4626
_fetchAll@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:29:26330
findAll@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:29:25941
model@http://somecooldomain.com:8181/assets/beehive-admin-a5b1e40caf9c5a7c62f689308573a1d0.js:1:27676
deserialize@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:13:17889
v@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:22:22827
runSharedModelHook@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:23:2544
getModel@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:23:4724
u/<@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:22:21338
k@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:23:13161
A@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:23:13247
E@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:23:13064
invoke@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:7:14876
flush@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:7:15412
flush@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:7:16174
end@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:7:16519
run@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:7:17649
join@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:7:17715
l.join@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:12:21289
l.bind/<@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:12:21495
d@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:5:28738
o/</p<@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:5:29052
setTimeout handler*o/<@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:5:29265
l@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:5:26983
fireWith@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:5:27749
fire@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:5:27785
l@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:5:26983
fireWith@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:5:27749
ready@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:5:30707
d@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:4:21059
EventListener.handleEvent*@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:5:30865
@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:4:19849
@http://somecooldomain.com:8181/assets/vendor-b3fb1a9072b30aa6b2b5a5a6f72c2d21.js:4:19854

AND! You know what?) this logged code fetching EXACTLY this endpoint (in curl to show an issue explicitly):

curl 'http://localhost:8181/v1/hives' \
-H 'Accept: application/json, text/javascript, */*; q=0.01' \
-H 'Referer: http://somecooldomain.com:8181/' \
-H 'Origin: http://somecooldomain.com:8181'

Docker image: fribbledom/beehive:latest@sha256:9549cf6ffbe26f743e22fc2a43e7f516d18c077a4fc382132af8bdab9f736d97 Entry point: /bin/sh -c /go/bin/beehive -config /conf/beehive.conf

quenbyako commented 3 years ago

I found also CANONICAL_URL env, which is, you know, looks pretty dumb, cause you can already predict canonical url from web browser already. and, also, setting custom CANONICAL_URL isn't working! script anyway tries to fetch localhost endpoint

muesli commented 3 years ago

If you know a solution around CANONICAL_URL I'll happily accept a pull request. Setting a custom CANONICAL_URL is working just fine, though. I tried it a minute ago with the latest beehive:latest. Please give us a bit more information how you're exactly invoking Beehive. Feel free to replace the actual domain name with foobar.com or something similar.

quenbyako commented 3 years ago

@muesli sure, i'll try to experiment, and if i found any issue on backend, i'll let you know (cuz i don't work with js, sadly)

quenbyako commented 3 years ago

@muesli yikes, i found pretty bad code here.

Looks like it changing html page via bytes replacer (which is SO SO BAD idea). that's why it doesn't change canonical url i think.

Also, it doesn't so necessary to include hostname in html page (but url path is pretty required), so maybe api package needs some refactoring? i can do that in free time maybe

muesli commented 3 years ago

Can you elaborate a bit more? I'm not sure what issue you're seeing.