I can use Angular 2 to create basic front-end applications and can use python to create back-ends with endpoints on Google App engine. I can't however seem to figure out how to put the two together and deploy them with the cloud SDK.
Here is a basic example where I can't even host a simple angular2 app with no back-end calls on GAE. I have taken the dist folder after building with angular2 CLI and tried to connect to it with the app.yaml file. It seems to work in the browser developer (dev_appserver.py app.yaml) although I get some 404 errors in SDK with the GET requests to do with my index.html file I think. I then create a blank index.yaml file and try to deploy it but get a 404 Error at the appspot.com location. This is the app.yaml file:
application:
version:
runtime: python27
threadsafe: true
api_version: 1
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: (.*)/
static_files: dist\1/index.html
upload: dist
- url: (.*)
static_files: dist\1
upload: dist
I really have no idea what I am doing wrong. Do I need some kind of a main.application python back-end to connect to the dist files or? Do I need to include node modules or some other kind or files from Angular2? Any help would be massively appreciated! Thanks
Replace your app.yaml with the following. It will work!
I now update the handlers in my app.yaml file to look like this for static uploads to the google cloud platform. There was issues with Angular Router if the regular expression wasn't like this. Dist folder is output from angular cli
ng build
:UPDATE:
For production
ng build --prod
, this is how my app.yaml file would look:I would add any other file types in the dist folder to the regex grouping characters in the first handler:
(gif|png|jpeg|jpg|css|js|ico)
For the latest versions of Angular 4 and App Engine I built the following:
Looking for feedback on how this could be improved.
For Angular 6, the file structure changed somewhat. The following is based on @Rob's answer, but updated for an Angular 6 with a service-worker enabled. Be sure to replace "my-app" with the folder name of your app.
first build your angular project by running the following command
the after the build is done create an app.yaml file in the root folder of your project and paste the following code:
after this run:
It looks like your regular expression match is in the wrong spot. Try this format:
This comes from testing and some oddities we encountered while creating the Static Hosting tutorial on App Engine.