Serve Static File

Want to serve a static file at the root of your Discourse server?

Here’s what to do. In the bottom of your app.yml file, down in the custom commands section, do something like this:

## Remember, this is YAML syntax - you can only have one block with a name
run:
  - exec: echo "Beginning of custom commands"
  - file:
     path: /var/www/discourse/public/myfile.txt
     chmod: "+r"
     contents: |
       Stuff that's in the file goes here.
  - exec: echo "End of custom commands"

And . /launcher rebuild app
The file will then be accessible as http://yourserver.com/myfile.txt

12개의 좋아요

What is an actual example of where one would want to do this?

2개의 좋아요

Personally i find this really useful. Not to mention that this kind of static file, gives you way more opportunities to use your imagination, files, maybe other website service that you can run as static – etc :smiley:

2개의 좋아요

I’m wondering what “stuff” limitations there are.

contents: |
       Stuff that's in the file goes here.

I imagine simple text strings work well enough, though I also imagine for this to be more useful, markup, links, images, etc. would be desired. I suspect that the more closely “stuff” approaches being a web page the more difficult it would be to not break.

@pfaffman what is your use case and what degree of complexity have you been able to do successfully?

1개의 좋아요

This can also help verifying ownership of the site, e.g. with Google Webmaster Tools :slight_smile:

5개의 좋아요

Site ownership verification can be done with a meta tag in the head as well.

6개의 좋아요

Well, you’ve seen the actual examples that I know about. There are ways not to need it, but I’ve wanted to do this a few times and finally bothered to figure it out. :slight_smile:

3개의 좋아요

매우 흥미롭고 유용합니다. 이 기능을 조정하여 여러 파일을 폴더에 덤프(dump)하여 접근할 수 있게 할 수 있을까요? 예를 들어 /var/www/discourse/public/img를 만들어 yourserver.tld/img/step_1.png를 쉽게 서빙하고, 서버로 scp를 통해 전송되거나 다른 방식으로 업로드된 수많은 후속 파일들을 처리할 수 있도록 하는 것이 가능합니다.

1개의 좋아요

왜 애플리케이션 서버를 사용해 파일을 서빙하나요? 다른 곳에 저장하고 서빙하는 것이 더 저렴하지 않을까요?

제 특정 사용 사례에서는 그렇지 않습니다. 관리자 목적으로 특히 유용한 특정 파일들에 대해 이렇게 하기를 선호합니다.

1개의 좋아요

이 목적으로 Cloudflare Worker를 사용 중입니다:

2개의 좋아요

유료 호스팅은 어떻게 되나요? 이걸로 가능한 방법이 있을까요?

프로젝트에 대해 Semrush를 사용하여 도메인 소유권을 확인해야 합니다. 다른 Semrush 사용자가 제 사이트를 감사하지 않도록 하고 싶습니다.

원래 방법이 작동하지 않으면 나중에 이 방법을 시도해볼게요 :slight_smile:

의사 말씀이 더 마음에 들어요 :smiley:

1개의 좋아요