Amplify-console: redirect for a static file

Created on 1 Nov 2019  路  16Comments  路  Source: aws-amplify/amplify-console

* Please describe which feature you have a question about? *
Using Amplify console to host our SPA web site

I need to provide access to this static file:
https://cloud-coop.info/.well-known/apple-developer-merchantid-domain-association

apple-developer-merchantid-domain-association is just a static text file.

I have this statement in amplify.yml which I am pretty sure gets the file on the site (it is in the artficts if I look there)

 artifacts:
        baseDirectory: dist
        files:
            - '**/*'
            - '.well-known/*' 

I setup the following redirects:

  {
        "source": "https://cloudcoop.info",
        "target": "https://www.cloudcoop.info",
        "status": "302",
        "condition": null
    },
    {
        "source": "</^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$)/>",
        "target": "/index.html",
        "status": "200",
        "condition": null
    }

when I access https://cloud-coop.info/.well-known/apple-developer-merchantid-domain-association i get a 404 error

If I access it in a local host dev server
https://localhost:4200/.well-known/apple-developer-merchantid-domain-association
i see the file just fine.

Thanks for any help.

* Provide additional details*

question

Most helpful comment

We had the same issue.
We solved it by renaming the
.well-known/apple-app-site-association ->
well-known/apple-app-site-association.json
(notice the folder rename and the extension added)

Then added the rewrite rule

    {
        "source": "/.well-known/apple-app-site-association",
        "target": "/well-known/apple-app-site-association.json",
        "status": "200",
        "condition": null
    },

If we didn't do it this way, we had an issue with the trailing / getting added and the rewrite rules weren't getting honored. Secondly, we also noticed the .well-known directory was getting ignore by amplify and would not upload correctly, so we had to change it to well-known.

All 16 comments

I ran into something similar when writing the rewrite rules, it looks like the regex ^[^.]+$|\\.(?!(css|gif|ico|jpg|js|png|txt|svg|woff|ttf|map|json)$)([^.]+$) is blocking your file.

^[^.]+$ 

is saying from start of the line to the end of the line, don't match anything with a .

you can go to regex101.com and input your regex and test different strings, hope this helps.

https://share.getcloudapp.com/KouQEREN

thanks for the advice @tmbtech . I think the point of that redirect is for a SPA to allow all those extenstions to pass. and redirect everthing else. This allows routing to work.

I just cant get how to get the route https://cloud-coop.info/.well-known/apple-developer-merchantid-domain-association to rewrite. I think its falling all the way throught the rewrite rule logic to fire a 404. It is not hitting the regex rule because that would rediret to index.html

Other ideas?

@DavidNelsonCordelia is the .well-known/ folder located inside your dist folder? You have set your baseDirectory to dist.

@Joycehao19 Yes. .well-known/ is in the dist folder. I also checked the build artifacts and it was clearly there

David

@DavidNelsonCordelia we're investigating this. Here's a workaround provided by @afladmark: https://github.com/aws-amplify/amplify-console/issues/278#issuecomment-559628252

Are there any updates on this? I just spent the morning trying to figure out the same issue.

We had the same issue.
We solved it by renaming the
.well-known/apple-app-site-association ->
well-known/apple-app-site-association.json
(notice the folder rename and the extension added)

Then added the rewrite rule

    {
        "source": "/.well-known/apple-app-site-association",
        "target": "/well-known/apple-app-site-association.json",
        "status": "200",
        "condition": null
    },

If we didn't do it this way, we had an issue with the trailing / getting added and the rewrite rules weren't getting honored. Secondly, we also noticed the .well-known directory was getting ignore by amplify and would not upload correctly, so we had to change it to well-known.

@swaminator any update on this?

I have the same problem trying to delegate matrix configs
/.well-known/matrix/client
/.well-known/matrix/server

Solved with removing the . and adding file extensions like @tmbtech said! Hugely frustrating behavior of amplify!

Is it really working?
Apple specifically say that we should not use any extension... nor redirection...

Next, add the Apple App Site Association file to your website. To do this, create a file named apple-app-site-association (without an extension).

You must host the file using https:// with a valid certificate and without using any redirects.

cf developer.apple

For anyone who lands here, we fixed the issue. It was a bug with dot files not deploying.

While the file appears to be deploying, it seems Amplify is still trying to add a trailing slash to the end of the file. Following the solution mentioned above worked for me.

Is there a way to not have the trailing / at the end of the file? Apple clearly says it won't allow redirects. Can someone confirm if this has worked for the use with universal links?

This issue still exists for me. Amplify seems to be ignoring . in the path.
I tried to add a redirect rule, but it seems that Amplify automatically removes the dot in the path.

We had the same issue.
We solved it by renaming the
.well-known/apple-app-site-association ->
well-known/apple-app-site-association.json
(notice the folder rename and the extension added)

Then added the rewrite rule

    {
        "source": "/.well-known/apple-app-site-association",
        "target": "/well-known/apple-app-site-association.json",
        "status": "200",
        "condition": null
    },

If we didn't do it this way, we had an issue with the trailing / getting added and the rewrite rules weren't getting honored. Secondly, we also noticed the .well-known directory was getting ignore by amplify and would not upload correctly, so we had to change it to well-known.

I tried the same thing. I had to create two new redirect rules. Now I can access the file, but Apple validator still complain.

This is the error on Apple Validator:

Error no apps with domain entitlements
The entitlement data used to verify deep link dual authentication is from the current released version of your app. This data may take 48 hours to update.

Also having the trailing slashing issue. Cannot find any solution to this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nhhaidee picture nhhaidee  路  3Comments

kontrol-debug picture kontrol-debug  路  4Comments

BardiaN picture BardiaN  路  4Comments

nomiddlename picture nomiddlename  路  4Comments

dongjason1 picture dongjason1  路  3Comments