roeland
roeland

Reputation: 6336

SPA on GAE. Best way to host frontend

I'm developing a Single Page Application on Google App Engine. The backend will be in Go and the frontend in React. For the backend I would like to use Google Endpoints. This can't be used with a custom domain so I will use CORS: https://code.google.com/p/googleappengine/issues/detail?id=9384

But now the question is how should I host the frontend. These are just static files. Should I use a separate GAE project for this? Is there a better solution?

Upvotes: 0

Views: 825

Answers (1)

Paul Collingwood
Paul Collingwood

Reputation: 9116

GAE can easily serve static files, just mark them as static in your app.yaml.

https://cloud.google.com/appengine/docs/go/config/appconfig#Go_app_yaml_Static_file_pattern_handlers

For efficiency, App Engine stores and serves static files separately from application files. Static files are not available in the application's file system.

Example:

handlers:

# All URLs ending in .gif .png or .jpg are treated as paths to static files in
# the static/ directory. The URL pattern is a regexp, with a grouping that is
# inserted into the path to the file.
- url: /(.*\.(gif|png|jpg))$
  static_files: static/\1
  upload: static/.*\.(gif|png|jpg)$

I believe they are served from Google's general infrastructure, from a datacenter near to the end user. So it seems like a good idea to do it like this.

In fact for a SPA you will find instances will not spin up if you just serve static files :)

CORS support details also available on that link.

Upvotes: 1

Related Questions