Skip to content

Adding support for hosting with URL prefix #1357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 41 commits into from
Jun 4, 2025

Conversation

flowkclav
Copy link
Contributor

@flowkclav flowkclav commented Apr 25, 2025

Closes #163. Adding support for hosting with URL prefix to make reverse-proxy setup on sub-path possible.

Starting silverbullet server specifying a "prefix" (or "context root") in environment variable SB_URL_PREFIX will cause the application to be hosted on the specified prefix. This allows sub-path configuration when setting up reverse proxies (e.g. https://myserver/sb/ -> http://localhost:3000/sb/ )

Summary of changes:

  • server:
    • Hono configured to serve on the prefix, if specified
    • Prefix is removed from incoming URLs in server endpoints for the application to function normally
    • Prefix is added to outgoing redirects
    • Prefix is set as path in authentication cookies
    • Injection of the prefix in the base element of index.html and auth.html
  • client:
    • Switching from "absolute" URLs (i.e. host-relative, e.g. /myresource) to page-relative URLs (e.g. myresource)
    • Using document.baseURI instead of location.origin|host when constructing URLs

NOTES:

  • Running the formatter modified a file I did not otherwise touch, I did not include it in this PR.
  • Likewise, the test I added and modified pass but another test is failing, at least on my setup (JSON utils => ./plug-api/lib/json.test.ts:4:6 fails with Actual 2023-05-02 / Expected 2023-05-03. Probably a timezone thing). I left it alone.

@flowkclav flowkclav force-pushed the 163-support-subpath branch from bed4fb6 to 0c972e6 Compare May 1, 2025 00:10
@zefhemel
Copy link
Collaborator

zefhemel commented May 1, 2025

Thanks for this. I need the time to properly tests this. I anticipate a lot of edge cases and places where being hosted at the root is implicitly assumed.

@zefhemel zefhemel self-assigned this May 1, 2025
@flowkclav
Copy link
Contributor Author

Absolutely! I am fairly new to silverbullet so it is very possible that I missed something. As if to illustrate my point, I just realised I never tested in offline mode. I just did and sure enough, the service_worker.ts will need tweaking. And unlike the rest of the client code, it doesn't have access to document.baseURI to derive the prefix. I'll try to take a closer if I have some more time.

flowkclav and others added 24 commits May 2, 2025 19:22
* Add more tests for week calculation

* Fix week calculation

* Add more tests
* Implement Lua built-in function os.difftime

* Test os.difftime

---------

Co-authored-by: Zef Hemel <[email protected]>
* Generate version from git describe at build time

* Add 2.0-beta prefix

* Use Deno.Command instead of Deno.run
Configurable with queryCollation, default value maintains old behaviour.
Added tests, schema, example settings, and documentation to query page.

Close: silverbulletmd#614
Close: silverbulletmd#1316
…ulletmd#1386)

* Add global Lua function 'some'

Moved documentation for 'each' function to non-standard section.

* Revert "Add optional argument to template.each for empty collection output (silverbulletmd#1359)"

This reverts commit b73dade.

* Reimplement silverbulletmd#1359 using 'some' function
…d#1397)

The documentation, example, and other function names use
`event.listEvents`, but `event.list` is being registered with the
client.
Also add a 10px margin below the header to maintain consistent spacing
around the widget contents.
…d#1392)

* Add optional priority attribute to PageCreatingContent

* Minor simplification

* Fix comments

* Revert changes

* Add pageEventHandlers
@zefhemel zefhemel merged commit 766fb96 into silverbulletmd:main Jun 4, 2025
1 check passed
@zefhemel
Copy link
Collaborator

zefhemel commented Jun 4, 2025

Thanks a lot for this effort, a lot of people have asked for it! I'm sure there may be subtle issues, but based on some testing this seems to work great!

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

Successfully merging this pull request may close these issues.

Support hosting at a URL path
10 participants