[GH-ISSUE #248] Support relative paths for attachments #195

Closed
opened 2026-05-07 00:21:18 +02:00 by BreizhHardware · 4 comments

Originally created by @Curid on GitHub (May 11, 2022).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/248

"base-url" is the root URL for the ntfy server; this is needed for the generated attachment URLs

If the client knows the URL of the server, why does the baseURL need to be configured manually?

Originally created by @Curid on GitHub (May 11, 2022). Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/248 `"base-url" is the root URL for the ntfy server; this is needed for the generated attachment URLs` If the client knows the URL of the server, why does the baseURL need to be configured manually?
BreizhHardware 2026-05-07 00:21:18 +02:00
Author
Owner

@binwiederhier commented on GitHub (May 11, 2022):

There are many reasons, not all of them are rock solid. Here's the gist of it:

  • When you publish a message via PUT/POST, the client doesn't pass the base URL in the HTTP request. Especially if passing through a proxy, the server would have to re-assemble the URL based on the HTTP Host header and the protocol. The re-assembled URL doesn't always match the publicly available URL. For instance, the ntfy.sh server runs on an HTTP port, but is proxied through nginx on HTTPS, so for all that the ntfy server is concerned, it's on HTTP, though that is not true.
  • Other entry points (such as SMTP) don't even have the Host header, so they absolutely need a base URL.
  • We could solve this problem by returning the relative URL path (e.g /file/abcdefg.jpg instead of https://...), but then the clients would have to differentiate between relative and absolute URLs. Setting the base URL in the server config seems much easier than that.

Makes sense? Why are you asking about this?

<!-- gh-comment-id:1124185712 --> @binwiederhier commented on GitHub (May 11, 2022): There are many reasons, not all of them are rock solid. Here's the gist of it: - When you publish a message via PUT/POST, the client doesn't pass the base URL in the HTTP request. Especially if passing through a proxy, the server would have to re-assemble the URL based on the HTTP `Host` header and the protocol. The re-assembled URL doesn't always match the publicly available URL. For instance, the ntfy.sh server runs on an HTTP port, but is proxied through nginx on HTTPS, so for all that the ntfy server is concerned, it's on HTTP, though that is not true. - Other entry points (such as SMTP) don't even have the `Host` header, so they absolutely need a base URL. - We _could_ solve this problem by returning the relative URL path (e.g `/file/abcdefg.jpg` instead of `https://...`), but then the clients would have to differentiate between relative and absolute URLs. Setting the base URL in the server config seems much easier than that. Makes sense? Why are you asking about this?
Author
Owner

@Curid commented on GitHub (May 11, 2022):

When you publish a message via PUT/POST, the client doesn't pass the base URL in the HTTP request.

Does the server need to know the base URL for messages to be published?

Makes sense? Why are you asking about this?

I want to embed ntfy in a web app and I've been careful to make all paths in the app relative so users wouldn't need to specify a baseURL.

How about putting @ in front of relative paths and have the clients replace it?

if path[0] == "@" {
  path = calculatedPath + "/" + path[1:]
}
<!-- gh-comment-id:1124205801 --> @Curid commented on GitHub (May 11, 2022): > When you publish a message via PUT/POST, the client doesn't pass the base URL in the HTTP request. Does the server need to know the base URL for messages to be published? >Makes sense? Why are you asking about this? I want to embed ntfy in a web app and I've been careful to make all paths in the app relative so users wouldn't need to specify a baseURL. How about putting `@` in front of relative paths and have the clients replace it? ``` if path[0] == "@" { path = calculatedPath + "/" + path[1:] } ```
Author
Owner

@binwiederhier commented on GitHub (May 11, 2022):

Does the server need to know the base URL for messages to be published?

If you check for where config.BaseURL is used, you can see that it's in two places:

  • To calculate the attachment URL
  • To calculate the topic URL (in the email footer)

The attachment URL is stored in the DB and returned to the client. So the base URL has to be known to the server at time of publishing. If you don't use either of these features, you don't need to specify it.

I want to embed ntfy in a web app and I've been careful to make all paths in the app relative

The web app will not work unless it's at the doc root. I've tried very hard to make it relative in React, but I couldn't make it work and eventually gave up.

<!-- gh-comment-id:1124219981 --> @binwiederhier commented on GitHub (May 11, 2022): > Does the server need to know the base URL for messages to be published? If you check for where `config.BaseURL` is used, you can see that it's in two places: - To calculate the attachment URL - To calculate the topic URL (in the email footer) The attachment URL is stored in the DB and returned to the client. So the base URL has to be known to the server at time of publishing. If you don't use either of these features, you don't need to specify it. > I want to embed ntfy in a web app and I've been careful to make all paths in the app relative The web app will not work unless it's at the doc root. I've tried very hard to make it relative in React, but I couldn't make it work and eventually gave up.
Author
Owner

@Curid commented on GitHub (Jun 6, 2022):

@binwiederhier I need some help to implement this.

In the WebUI I'm thinking of replacing the @ before they are saved in the database here Does there need to be 2 methods for adding notifications or can I combine them into one?

For the Android side I have no idea.

<!-- gh-comment-id:1147700277 --> @Curid commented on GitHub (Jun 6, 2022): @binwiederhier I need some help to implement this. In the WebUI I'm thinking of replacing the `@` before they are saved in the database [here](https://github.com/binwiederhier/ntfy/blob/4baf6996c5cbab89a7279c4cfe3a24e55ae820b0/web/src/app/SubscriptionManager.js#L66) Does there need to be 2 methods for adding notifications or can I combine them into one? For the Android side I have no [idea](https://github.com/binwiederhier/ntfy-android/search?q=addNotification&type=).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ntfy#195
No description provided.