7

We are currently using GitHub Pages as a simple API mock server. We put all mock files under docs/ and simply GET username.github.io/project/api/someAPI to retrieve data. However, by default, the Content-Type returned by GitHub Pages is application/octet-stream instead of application/json for files with no extensions, therefore our frontend code throws errors when parsing the result.

I want to know is there any way to change the returned Content-Type for files with no extension on GitHub Pages?

1
  • Same issue here, but with a MPEG-4 video coming back with either no content type (IE, Edge) or a text content type (Chrome). Video plays in Chrome, not in IE or Edge. Commented Jul 20, 2018 at 20:20

1 Answer 1

3

https://docs.github.com/en/pages/getting-started-with-github-pages/about-github-pages#mime-types-on-github-pages suggests this is impossible:

you can't specify custom MIME types on a per-file or per-repository basis

From experimentation, you can create subdir/index.json which will cause https://owner.github.io/repo/subdir/ to successfully (200) serve content with type application/json. But https://owner.github.io/repo/subdir will serve a 301 redirect, which an API client may not tolerate.

Taking a hint from https://jekyllrb.com/docs/configuration/options/ I tried creating _config.yml

include: .htaccess

and .htaccess

ForceType application/json

without success. I also found https://github.com/jekyll/jekyll/issues/5454 suggesting this is not possible.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.