Search code examples
firebasefirebase-hosting

How do I change the content type to application/json for spesific files?


For Matrix homeserver (on Modular.im) you need to have 2 files:

  1. domain.tld/.well-known/matrix/server
  2. domain.tld/.well-known/matrix/client

...they also need to be application/json instead of firebase's default application/octet-stream. How do I change that?

The current firebase.json's not wroking solution is from this answer.

$ cat firebase.json 
{
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {

        "source": "/.well-known/matrix/server",
        "destination": "/.well-known/matrix/server",
        "content-type": "application/json",
        "code":200
      },
      {

        "source": "/.well-known/matrix/client",
        "destination": "/.well-known/matrix/client",
        "content-type": "application/json",
        "code":200
      }
   ]
  }
}
$ firebase deploy

=== Deploying to 'dh'...

i  deploying hosting
i  hosting[dh]: beginning deploy...
i  hosting[dh]: found 19 files in public
✔  hosting[dh]: file upload complete
i  hosting[dh]: finalizing version...
✔  hosting[dh]: version finalized
i  hosting[dh]: releasing new version...
✔  hosting[dh]: release complete

✔  Deploy complete!

Project Console: https://console.firebase.google.com/project/dh/overview
Hosting URL: https://dh.firebaseapp.com
$ curl -v https://domain.tld/.well-known/matrix/client 2>&1 | grep content-type
< content-type: application/octet-stream

Solution

  • The answer you came across is incorrect. You need to specify custom headers:

    {
      "hosting": {
        "headers": [
          {
            "source": "/.well-known/matrix/*",
            "headers": [
              {"key": "Content-Type", "value": "application/json"}
            ]
          }
        ]
      }
    }