Need relative URLs for uploaded images

How can I get Discourse to generate relative URLs for uploaded images?

I have a site that is available over HTTPS and a TOR .onion and I need a way to get images working for both.

How can I configure Discourse so that upload:// URLs are converted to relative URLs in the <img> tag? Where (which source file) does this URL generation take place?

I don’t think relative image URLs is a supported configuration, and that might be a very difficult change cc @sam

Just to clarify:

Uploading works correctly both from the HTTPS domain and the TOR hidden service .onion but the actual HTML generated for a post uses a full URL which is a problem.

I’m assuming somewhere there is some code that does something like

 '<img src="' + Discourse.base_url_no_prefix + '/uploads/....jpg' + '">'

and I need it to generate

 '<img src="' + '/uploads/....jpg' + '">'

Would playing with absolute_without_cdn be too low-level and affect too many things?

The URL needs to be relative because:

  • A normal browser cannot access the .onion URL.
  • Cannot access the normal site over TOR because it is behind DDoS protection. And even if it worked, I don’t want to leak details to TOR exit nodes.

This would require some internal changes, I am somewhat sympathetic cause it makes life a bit easier when changing domain names for sites that do not use A CDN.

Would have to be something like, IF no CDN configured then cook a relative url.

I assume you only need to set this up when the configuration is changed?

Imagine having

'<img src="' + Discourse.cdn_url_no_prefix + '/uploads/....jpg' + '">'

When there is no CDN configured then Discourse.cdn_url_no_prefix can simply be a empty string.

Does that mean that there is a chance you can implement this in the (near) future?

@sam의 의견에 동의하며, 한 마디 더 보태자면, 도메인 관련 문제로 이미 몇 번의 혼란을 겪었습니다. 따라서 상대 URL은 분명히 필요합니다.

상대 경로 내부 링크를 지지하는 목소리를 더하고 싶습니다. 현재 저는 같은 사이트의 다른 토픽을 참조할 때 전체 URL을 사용하고 있습니다.

실제로 저희 사이트는 최근에 도메인을 변경했습니다(현재 리다이렉트가 활성화되어 있음):

그리고 저희의 새로운 호스팅 제공업체 Communiteq(구 DiscourseHosting)은 이 변경 사항을 반영하기 위해 저희 데이터베이스를 sed 명령으로 처리해 주셨습니다.

현재 상태에 대해 기술적인 이유가 있을까요? 미래에 %{THIS}/t/000과 같은 것을 사용할 수 있을까요? 개발자로서 절대 경로(absolute paths)는 보통 저를 긴장하게 만듭니다. 또한, aforementioned 마이그레이션의 일부로 저희가 수행한(또는 적어도 더 엄격하게 적용한) http:에서 https:로의 전환 문제도 있습니다. 이는 @mreach의 사례와 매우 유사해 보입니다.

항상처럼, 훌륭한 제품을 만들어 주신 discourse 팀에 진심으로 감사드립니다. R.

도메인이 변경될 때, 영향을 받는 모든 게시물에서 대상 검색 및 치환을 실행하는 것은 일반적으로 큰 문제가 되지 않습니다.