Cannot access contents of wwwroot folder in Google App Engine

Viewed 207

I have a fairly standard .net core MVC application built on Visual Studio for Mac. I have published may simalar projects to Azure App Services.

I'm now trying to publish this MVC app to Google App Engine. It publishes and runs, but none of the static content from the wwwroot folder is accessible from the browser - all file paths return 404.

I've confirmed the files are being copied to the server. Via SSH I run sudo docker exec -it gaeapp /bin/bash

In the directory I land in, I see the following:

DnsClient.dll                              
Dockerfile                                 
... (project dlls)
app.yaml
appsettings.json
bundleconfig.json
publish
runtimes
source-context.json
web.config

In the publish directory I see:

DnsClient.dll
... (project dlls)
app.yaml
appsettings.json
bundleconfig.json
runtimes
web.config
wwwroot

wwwroot contains all the files I expect. I've tried copying files out of wwwroot to various levels of the tree, but still cannot access the files.

Here's my app.yaml in case that helps:

runtime: aspnetcore
env: flex

# This sample incurs costs to run on the App Engine flexible environment. 
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/python/configuring-your-app-with-app-yaml
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10
env_variables:
  # The __ in My__Greeting will be translated to a : by ASP.NET.
  My__Greeting: Hello AppEngine!root@c2d2b26894e2:/app# 

Any ideas how I might fix this?

More Info

In case there was an issue with my project, I created a new MVC project from the VS template and published this. Same issue, as shown in the screenshot below. Tried with default template, plus added app.UseDefaultFiles(); as suggested in an answer.

Screenshot of page with resources 404ing

So, I assume the issue is in Google or the deployment...

1 Answers

In order to allow the an app engine flexible for dotnet to serve static files you have to allow it by using:

app.UseDefaultFiles();
app.UseStaticFiles();

On your main file. This is documented here.

I don't recommend it to do it if you're generating your files dynamically and putting them on the wwwroot folder, since one instance could have the files generated, but if another one wakes up it could be possible that the file isn't found there. For that kind of situation I suggest to use Cloud Storage as an alternative to a CDN

Related