Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set correct content-type for apple-app-site-association file on Nginx/Rails

In order to set up universal links for an iOS app, I have created an apple-app-site-association file, and placed it in the /public directory of my Rails app.

I can curl it at the correct address, but it returns the wrong content type. Instead of application/json or application/pkcs7-mime it returns application/octet-stream, as you can see in the response here:

curl -i https://example.com/apple-app-site-association

HTTP/1.1 200 OK
Server: nginx/1.10.1
Content-Type: application/octet-stream
Content-Length: 245
Last-Modified: Mon, 21 Nov 2016 12:45:00 GMT
Strict-Transport-Security: max-age=31536000

{
  "applinks": {
    "apps": [],
    "details": [
      {
        "appID": "APPPREFIX.com.mycompany.app",
        "paths": [
          "/home*"
        ]
      }
    ]
  }

I am attempting to specify a Content-Type in the nginx configuration:

/etc/nginx/sites/sites-available/sitename: 

server {
   ...
   location /apple-app-site-association {
      default_type application/pkcs7-mime;
   }
}

I have saved this change and restarted nginx. This doesn't make any difference to the response from curl. I've also tried location /public/apple-app-site-association {} and a few other variations, to no effect.

What is the correct way to set up nginx to deliver this file with the correct content type?

like image 766
Ali H Avatar asked Nov 21 '16 16:11

Ali H


1 Answers

This worked for me within .htaccess:

<FilesMatch "apple-app-site-association">
    ForceType application/json
</FilesMatch>
like image 133
Yaron Avatar answered Apr 29 '23 12:04

Yaron