PHP App Engine Flex serving SPA and API

24 views
Skip to first unread message

Chris Fremgen

unread,
Jan 16, 2018, 10:57:32 AM1/16/18
to Google App Engine

My goal is to serve a SPA and PHP api on the same site. I would like to be able to browse the website at mywebsite.com, and request api calls at mywebsite.com/api/.

My directory structure is:

public
|
+-- index.html 
+-- api
     |
     index.php


My app.yaml:

runtime: php
env: flex

runtime_config:
  document_root: public


Navigation to mywebsite.com gives a 404 because public/index.php doesn't exist.



So I tried this app.yaml:

runtime: php
env: flex

runtime_config:
  document_root: public
  front_controller_file: index.html


And I can access mywebsite.com normally since index.html is the default file, but api/index.php is still 404.


Is something like this possible on App Engine php flex? I've read the docs, no mention on how to handle routing like this. https://cloud.google.com/appengine/docs/flexible/php/configuring-your-app-with-app-yaml


Thanks!

Yannick (Cloud Platform Support)

unread,
Jan 16, 2018, 7:17:40 PM1/16/18
to Google App Engine
Hello Chris, while bundling several different services inside of a single App Engine version is possible, it is not the recommended way to build your application.

The recommended method is to instead use several independent services, each running on a sub-domain of your website, and to implement a Microservice architecture.

That way you could have mywebsite.com be your SPA and api.mywebsite.com be your API. Would that suit your needs?
Reply all
Reply to author
Forward
0 new messages