Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Make build independent of base url #31

Open
Giszmo opened this issue Apr 6, 2022 · 6 comments
Open

Make build independent of base url #31

Giszmo opened this issue Apr 6, 2022 · 6 comments

Comments

@Giszmo
Copy link
Contributor

Giszmo commented Apr 6, 2022

Deploying the built files to anything but the root folder breaks links.

Expected behaviour: Easy deployment in existing server by dropping the compiled files into some sub folder of my otherwise working website. This is how I had https://github.com/arcbtc/nostr deployed in no time.

Actual behaviour:

[2022-04-06 13:10:28] ERROR `/js/962.0d5c7870.js' not found.
[2022-04-06 13:10:28] ERROR `/js/532.9c3f5fab.js' not found.
[2022-04-06 13:10:44] ERROR `/js/962.0d5c7870.js' not found.
[2022-04-06 13:10:44] ERROR `/js/532.9c3f5fab.js' not found.
...
@Giszmo
Copy link
Contributor Author

Giszmo commented Apr 6, 2022

c04c4d7#diff-1d7ff4f413e8862d32dfe18796e76517d15cdb33a09e11ce2dc65c07c11df1f6R48 appears to have introduced this issue.

Edit: commenting the line out doesn't help. It still adds absolute paths to the minified result.

@fiatjaf
Copy link
Owner

fiatjaf commented Apr 6, 2022

I deploy by dropping the ./dist/spa/ directory on a webserver and it works.

The problem is that you'll need to rewrite all URLs to serve the base index.html, otherwise linking directly to a profile or event will get you a 404. You can do that kind of rewrite in nginx or Caddy very easily, or on Netlify or these other static website servers.

@Giszmo
Copy link
Contributor Author

Giszmo commented Apr 7, 2022

Would it be easy to restore the arcbtc/nostr behavior so I can try to then fix what you describe in other ways? The JS should be trivially able to figure out its base path and use it dynamically from there. "do rewrite in Caddy or nginx" is just adding complexity that would be nice to strip away so more people drop it onto their servers/blogs/websites.

@fiatjaf
Copy link
Owner

fiatjaf commented Apr 8, 2022

I don't understand what you're saying. I don't understand the error you're facing. I don't understand what is the behavior you want me to restore. I don't know how arcbtc/nostr worked.

I'm telling you it works by just deploying the files to a static file server. The nginx rewrite part is a detail and not necessary.

If it is not working to just deploy the files, please tell me what is not working. I don't understand the logs you posted on the first message. If I had to guess I would say they are caused by a caching issue.

@Giszmo
Copy link
Contributor Author

Giszmo commented Apr 8, 2022

I have a website, so obviously that website has an index.html in its root folder that gets used if you navigate to website.com/. I now want to deploy nostr to website.com/nostr/ but the generated index.html includes /js/532.9c3f5fab.js and not a relative js/532.9c3f5fab.js or a magically correct absolute /nostr/js/532.9c3f5fab.js which obviously points to a file that does not exist. If that is not clear or not how it works on your end, I'll reproduce it.

Edit: You said it's clear but here is anyway what I did:

branle(master)$ podman run --rm --volume $PWD:/t -it node bash
root@de15c894139f:/# cd /t
root@de15c894139f:/t# yarn
root@de15c894139f:/t# 
exit
branle(master)$ cp -r dist/spa/ ../website.com/assets/branle

Now, surfing to http://localhost:4000/assets/branle/ the dev console in my browser says:

22:17:33.254 Loading failed for the <script> with source “http://localhost:4000/js/app.8cc937ea.js”. [branle:1:1](http://localhost:4000/assets/branle/)
22:17:33.254 Loading failed for the <script> with source “http://localhost:4000/js/vendor.0677838b.js”. [branle:1:1](http://localhost:4000/assets/branle/)

With arcbtc/nostr it just worked.

@fiatjaf
Copy link
Owner

fiatjaf commented Apr 8, 2022

It is clear now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants