2

I need to include the .well-known/assetlinks.json file in my AppEngine Web App. It is mandatory to enable App Links for my Android application as described here https://developer.android.com/training/app-links/index.html

I added this line in the appengine-web.xml file

<static-files>
    <include path=".well-known/assetlinks.json"/>
</static-files>

The problem is that it works in local

http://localhost:8384/.well-known/assetlinks.json

but not when I deploy the web app and it returns a 404 error.

http://www.example.com/.well-known/assetlinks.json

I suppose it could be a security restriction but I looked everywhere in the Google Cloud Platform Console and I didn't find anything about.

Someone have a solution to this problem? Thank you

Angelo Nodari
  • 365
  • 7
  • 14
  • 1
    It would appear that it's currently not possible to use static folders starting with a . in App Engine. – Will Calderwood May 17 '17 at 11:00
  • 1
    I've added a more generic solution to this problem here http://stackoverflow.com/a/44023751/654070 – Will Calderwood May 17 '17 at 11:38
  • If the server stores Public Certificate information, or Oauth information in the .well-known folder, REMOVING THE DOT from the .well-known folder will BREAK your OAuth/OIDC and anything else referencing assets in that folder. – Quadrivium Feb 11 '21 at 16:28

5 Answers5

0

In the past, I've encountered something similar, albeit with the python runtime.

This usually occurs during the upload/deployment of the app engine app where the correct MIME type cannot be accurately guessed. The file ends up being deployed as a regular binary file, application/octect(or not at all?). You can confirm if this is the case from your deployment logs.

If so, you'll have to supply a MIME type for json in the web.xml file

<mime-mapping>
  <extension>json</extension>
  <mime-type>application/json</mime-type>
</mime-mapping>
Jeffrey Godwyll
  • 3,787
  • 3
  • 26
  • 37
0

<static-files> and <mime-mapping> need to go in appengine-web.xml, not web.xml. Refer to the doc 'appengine-web.xml Reference' for details.

Adam
  • 5,697
  • 1
  • 20
  • 52
0

Still, the MIME type associations get set in web.xml, as stated on the mentioned page, at the “MIME types for static files” paragraph: “By default, static files are served using a MIME type selected based on the filename extension. You can associate custom MIME types with filename extensions for static files in web.xml using elements.”

George
  • 1,488
  • 1
  • 10
  • 13
0

AppEngine doesn't like the . at the start of the directory name (I tried a few combinations in the appengine-web.xml file, even <include path="**assetlinks.json" expiration="365d" /> with no luck). Interestly, it works fine when running on the dev server (Eclipse + Windows 10). It's only when you deploy it, does it fail.

The solution was to remove the . from the directory, and create a servlet that reads it. Then in your web.xml, map the servlet with the .. As described here: https://stackoverflow.com/a/44023751/418057

Craigo
  • 3,384
  • 30
  • 22
-1

Ok I found a solution by myself!

in appengine-web.xml use this configuration

<servlet>
    <servlet-name>Assetlinks</servlet-name>
    <servlet-class>api.servlets.WorkAroundHttpServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Assetlinks</servlet-name>
    <url-pattern>/.well-known/assetlinks.json</url-pattern>
</servlet-mapping>

and create a class WorkAroundHttpServlet that extends HttpServlet

public class WorkAroundHttpServlet extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {

        if (!req.getRequestURI().startsWith("/.well-known/assetlinks.json"))
        {
            resp.sendError(404);
            return;
        }

            File file= new File(getServletContext().getRealPath("/") +  "/assetlinks.json");

            resp.setContentType("application/json");
            resp.getOutputStream().print(FileUtils.readFileToString(file, "utf-8")); 
    }
}
Angelo Nodari
  • 365
  • 7
  • 14