ckolderup / postmarks

a single-user bookmarking website designed to live on the Fediverse
https://postmarks.glitch.me
MIT License
456 stars 38 forks source link

Allow setting the base URL of the site via .env #113

Closed ckolderup closed 9 months ago

ckolderup commented 9 months ago

As a documented hack I was previously requesting that people go into src/utils.js and override the definition of const domain. That worked okay but had some downsides:

  1. confused some people
  2. required people to fork the codebase when they might otherwise not need to
  3. was going to make the upgrade path more difficult, since pulling in the git changes would overwrite their changes and/or require manual git conflict resolution

This change provides a newly detected environment variable, BASE_URL, which you can (for example) set to the value bookmarks.example.com if you are setting the instance up to be available at the URL https://bookmarks.example.com. Because this takes precedence, you can even use it in a Glitch project, if you've signed up to beta test the upcoming custom domain feature.

If you don't set a BASE_URL, the code will look for a PROJECT_DOMAIN, which it will assume came from a Glitch container and form a base url of the format ${PROJECT_DOMAIN}.glitch.me, and if you have neither, it will assume that you're just doing some testing on localhost and use that for some URLs that get generated.

Closes #111 -- reached out to the issue creator to confirm.

steve-bate commented 9 months ago

FWIW, I had the same issue since I was self-hosting outside of Glitch. I think it's a good idea to use something like PUBLIC_BASE_URL so the name is less ambiguous (BASE_URL could refer to a local or public URL).

ckolderup commented 9 months ago

@steve-bate good point, thank you! Revising. And thanks for the review @benbrown.