I cant seem to find this anywhere.
What I have is an appengine project that just serves html pages. But it only correctly loads files when the filename is 'exactly' correct.
I.e. mywebsite.com/lastproject/ loads perfectly
but mywebsite.com/lastproject does not load at all
I want the website to load correctly when the trailing / is left out. What am I missing???
Here is my app.yaml
application: websitewithsubfolder
version: 1
runtime: python
api_version: 1
handlers:
- url: (.*)/
static_files: static\1/index.html
upload: static/index.html
- url: /
static_dir: static
#Shay means the line should be:
- url: (.*)
That is a route that handles all URL requests you will not get any 404 errors, and all Requests are handled by a static index.html page. Your second route will not ever be handled as it is more specific and after your generic route.
You want the more specific routes above your catch all routes.
application: websitewithsubfolder
version: 1
runtime: python
api_version: 1
handlers:
- url: /static
static_dir: static
- url: /favicon.ico
static_files: static/images/favicon.ico
upload: static/images/favicon.ico
mime_type: image/vnd.microsoft.icon
- url: /robots.txt
static_files: robots.txt
upload: robots.txt
- url: /(.*\.(gif|png|jpg))
static_files: \1
upload: (.*\.(gif|png|jpg))
- url: /static/css
static_dir: static/css
- url: /static/js
static_dir: static/js
- url: (.*)
static_files: static/index.html
upload: static/index.html
The app.yaml file above is more in line with what you want.
I suggest you read the app.yaml docs which go over this in more detail.
Your first mapping in the yaml file tells the AppEngine "every url that ends with / should be mapped to ...". You don't have any mapping to something that doesn't ends with /.
this will map everything to a folder named static/html (untested let me know if it works)
- url: /.*
static_dir: static/html
mime_type: text/html
Related
The question is very similar to How do I make Angular 2 routing work with App Engine on page refresh? but I do not have enough points to comment and it says not to put questions in answers.
Anyway same problem except it's a static hosted site on appspot with angular cli dist folder being used:
Project
|
+--dist
|
+--index.html
+--inline.js
+--inline.map
+--main.bundle.js
+--main.map
+--styles.bundle.js
+--styles.map
+--app.yaml
+--index.yaml
I tried changing my app.yaml to something similar to Dan's answer linked above but can't work it out? Here is the app.yaml file:
application:
version:
runtime: python27
threadsafe: true
api_version: 1
handlers:
- url: /(.*\.js)
static_files: dist/\1
upload: dist/(.*\.js)
- url: /(.*\.map)
mime_type: application/octet-stream
static_files: dist/\1
upload: dist/(.*\.map)
- url: /
static_files: dist/index.html
upload: dist/index.html
- url: /(.*)
static_files: dist/\1
upload: dist/(.*)
Thanks
try this handlers:
- url: /(.*\.(gif|png|jpg|css|js)(|\.map))$
static_files: dist/\1
upload: dist/(.*)(|\.map)
- url: /(.*)
static_files: dist/index.html
upload: dist/index.html
add file extensions in the first handler if your app uses more.
works for my app...
Built a personal blog using jekyll. Everything works well on local host. I do not want to deploy it on github. I prefer hosting on google app engine for some reasons.
I followed some instructions online and copied _site folder generated to my google app engine project.
this is how app.yaml looks like:
application: myblog
version: 1
runtime: python27
api_version: 1
threadsafe: yes
error_handlers:
- file: /404.html
handlers:
- url: /
static_files: _site/index.html
upload: _site/index.html
- url: /(.*)
static_files: _site/\1
upload: _site/(.*)
libraries:
- name: webapp2
version: "2.5.2"
when i run it locally on google app engine, only the index.html and some other files displays. others shows page not found. Is there anything I am not implementing properly ?
Well, I finally figure it out. It is a little trick anyway.
First in your _config.yaml file add:
permalink: /posts/:title/index.html
after that, run jekyll serve to generate the static file in _site folder. Copy the the post folder to _site/ in your app engine project.
Then, in your _config.yaml file change permalink to:
permalink: /posts/:title
run jekyll serve to generate the static file in _site. Copy the entire files generated excluding posts folder into _site/ into your app engine project.
then, make your appengine app.yaml look somewhat like this:
application: myblog
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /(.*\.js)
mime_type: text/javascript
static_files: _site/\1
upload: _site/(.*\.js)
- url: /(.*\.(jpg|png|ico))
static_files: _site/\1
upload: _site/(.*\.img)
- url: /(.*\.css)
mime_type: text/css
static_files: _site/\1
upload: _site/(.*\.css)
- url: /(.*\.(eot|svg|svgz|otf|ttf|woff|woff2))
static_files: _site/\1
upload: _site/(.*\.fonts)
- url: /
static_files: _site/index.html
upload: _site/index.html
- url: /(.+)/
static_files: _site/\1/index.html
upload: _site/(.+)/index.html
expiration: "15m"
- url: /(.+)
static_files: _site/\1/index.html
upload: _site/(.+)/index.html
expiration: "15m"
- url: /(.*)
static_files: _site/\1
upload: _site/(.*)
#- url: /((tags)|(archive)|(about)|(posts)|(fonts))/
libraries:
- name: webapp2
version: "2.5.2"
see example for clarification
I am trying to make an Angular 2 app running on App Engine Standard Environment. It works with the following app.yaml configuration when navigating within the app:
handlers:
- url: /api/.*
script: _go_app
- url: (.*)/
static_files: static\1/index.html
upload: static
- url: (.*)
static_files: static\1
upload: static
I can click on a link from / to /clients or /clients/234234 and it works fine.
However if I refresh the browser in a non base path e.g. http://myapp.appspot.com/clients/234234 then I get a 404 error. I guess I need to serve my index.html from all paths which is what I thought (.*)/ and (.*) would do.
How can I set up my handlers/app so I can use HTML5 routing and not let this happen?
I have a bunch of static files that need to be served so I added their mappings first. I also (most importantly) changed the way index.html was served:
handlers:
- url: /api/.*
script: _go_app
- url: /(.*\.svg)
static_files: static/\1
upload: static/(.*\.svg)
- url: /(.*\.js)
static_files: static/\1
upload: static/(.*\.js)
- url: /(.*\.map)
mime_type: application/octet-stream
static_files: static/\1
upload: static/(.*\.map)
- url: (.*)/
static_files: static/index.html
upload: static
- url: (.*)
static_files: static/index.html
upload: static
After deploying my first app engine app, I'm receiving Static file referenced by handler not found: index.html as an error in the logs. Here is my yaml file:
application: section-14
version: v1
api_version: 1
runtime: python27
threadsafe: yes
handlers:
- url: /bower_components
static_dir: bower_components
- url: /general
static_dir: general
- url: /projects
static_dir: projects
- url: /js
static_dir: js
- url: /styles
static_dir: styles
- url: /elements
static_dir: elements
- url: /images
static_dir: images
#here's the problem
- url: /
static_files: index.html
upload: /
#------------------
- url: /elements.html
static_files: elements.html
upload: /
I can travel to any of the other directories, and files located in those directories, without any problem. Also, if you look below the index entry, the elements.html route works also.
I noticed in other projects that people are defining a /static directory. Is that a requirement? My local environment serves this app without any issues as is.
Naming the directory static isn't a requirement. I do it because it makes the significance of the layout obvious (to me, at least).
Here's an app.yaml fragment from one of my apps that has a static home page and static assets.
handlers:
- url: /style/
static_dir: static/style
- url: /js/
static_dir: static/js
- url: /favicon.ico
static_files: static/favicon.ico
upload: static/favicon.ico
mime_type: image/x-icon
- url: /.+
script: main.app
- url: /
static_files: static/index.html
upload: static/index.html
The order is significant, as is the use of /.+ instead of /.* With the latter, requests for / would get routed to the main.app
Edited to add: Having a url mapping for a static favicon.ico is useful to prevent the request getting routed to your app, since this'll cause App Engine to spin up an instance when one isn't needed.
If i have a url like this www.myurl.com/test#test.com I would like to get the index.html
if I dont have the mail I want the same.
application: myapp
version: 1
runtime: python
api_version: 1
handlers:
- url: /AJAX
script: main.py
- url: /
static_files: static_files/index.html
upload: static_files
- url: /
static_dir: static_files
- url: /*
static_files: static_files/index.html
upload: static_files
If you change the last section in the handler group to
- url: /.*
static_files: static_files/index.html
upload: static_files
it should match any URL.