Where do I put my sitemap on appengine? - google-app-engine

I know for typical static file such as stylesheets app.yaml must contain the path to the directory holding said files. E.g.
- url: /stylesheets
static_dir: stylesheets
How do I go about adding a sitemap to GAE server?

this is what i did for my favicon, since it's a static file:
- url: /favicon.ico
static_files: media/img/favicon.ico
upload: media/img/favicon.ico
the xml sitemap is a static file too, so you may want to do the same:
- url: /sitemap.xml
static_files: my/folder/path/sitemap.xml
upload: my/folder/path/sitemap.xml
not completely sure about the upload line, tho. but my favicon didn't work in the first place without it
edit: if you want a dynamic sitemap, you could follow the instructions in this link to generate them everytime the sitemap page gets visited

In order to follow the best practices on App Engine I would recommend you to check this Boilerplate http://appengine.beecoss.com
Over there you will find where put sitemap.xml and many more files you need. This is the best way to do it.
- url: /(robots\.txt|humans\.txt|crossdomain\.xml|sitemap\.xml)
static_files: static/\1
upload: static/(robots\.txt|humans\.txt|crossdomain\.xml|sitemap\.xml)

Related

Google App Engine: Routing which appends .html

I'm deploying a React app to Google App Engine. Currently I need to append .html or /index.html to the requests but I would like to avoid this so I have clean routes.
For example, I can load mywebsite.com/docs/page1.html and mywebsite.com/docs/page1/index.html but I want to load mywebsite.com/docs/page1. The react app actually builds both of these duplicate pages so it appears this is somewhat default behaviour. The routing is only "broken" like this when I build, it works fine in the dev server.
Directory structure
- build/my_docs/
- css/
- img/
- js/
- docs/
- page1.html
- page1/
- index.html
app.yaml
runtime: python3
service: docs
handlers:
- url: /
secure: always
redirect_http_response_code: 301
static_files: build/my_docs/index.html
upload: build/my_docs/index.html
- url: /css/(.*)
static_files: build/my_docs/css/\1
upload: build/my_docs/css/(.*)
- url: /img/(.*)
static_files: build/my_docs/img/\1
upload: build/my_docs/img/(.*)
- url: /js/(.*)
static_files: build/my_docs/s/\1
upload: build/my_docs/js/(.*)
- url: /(.*\.(json|ico|xml))$
static_files: build/my_docs/\1
upload: build/my_docs/.*\.(json|ico|xml)$
- url: /docs/(.*)
static_files: build/my_docs/docs/\1
upload: build/my_docs/docs/(.*).html
# Trying to append .html to non css/img/js requests but it doesn't work!
I also tried to deploy the sample Docusaurus project to GAE with no app.yaml handlers, and I see the same undesired routing (need to append .html).
Are you satisfied with serving these html files as static docs, or should they be templates which you can pass content to?
First, in your / handler, there is no such file build/my_docs/index.html
Your /docs/(.*) handler appears to be fine. You say it works in dev but not in build? That sounds like a routing problem inside React. Check your React routing. Also, make sure you're resetting your browser cache frequently, as you may be caching old React code.
** EDIT **
Let's look at this handler:
- url: /docs/(.*)
static_files: build/my_docs/docs/\1
upload: build/my_docs/docs/(.*).html
If you request at the url /docs/page1, it is going to try to load the static file from the directory build/my_docs/docs/page1. So far, so good, as that directory exists.
The problem comes in the next line. You are asking to serve the static file build/my_docs/docs/page1.html, which does not exist in the directory specified. Try one of these:
- url: /docs/(.*)
static_files: build/my_docs/docs/\1
upload: build/my_docs/docs/(.*)/index.html
or:
- url: /docs/(.*)
static_files: build/my_docs/docs
upload: build/my_docs/docs/(.*).html
I other words, there is a mismatch between the static_files directory you specify and the location of the file you're trying to serve.

App Engine app.yaml handlers not working as expected

I am trying to set up a vue.js application with the vue router set in "history" mode. I also want to serve my back end APIs from the same app engine application. (e.g., if a user navigates to /some/path/in/the/app and refreshes the page or shares the link, the application will display the expected page)
here is my app.yaml:
runtime: python37
handlers:
- url: /api/.*
secure: always
script: auto
- url: /css
static_dir: www/css
- url: /js
static_dir: www/js
- url: /semantic
static_dir: www/semantic
- url: /img
static_dir: www/img
- url: /
static_files: www/index.html
upload: www/index.html
- url: /.*
static_files: www/index.html
upload: www/index.html
When I try to hit any of my api endpoints, the static index.html file is served instead of the response from the endpoint.
If the last route is omitted (url: /.*), then the api endpoints are served correctly, but the Vue.js app can only be entered from the "/" route and the deep links in the application do not work as expected
I am not looking to have a script in my application to serve the a static file.
note, this question is similar, but none of the answers addressed my situation:
AppEngine app.yaml config for single page apps
The trick was to follow a microservice architecture and split my application into two modules and define the routes in a dispatch.yaml file.
There is a sample project here:
App Engine Modules sample project

Google app engine website page structure

I made a website using Google app engine however, if I want to link from the main page to a different page in the folder structure, is does not load on the website.
The links are fine, they work if I check it on a browser directly from my drive. Do I need to put the entire folder in a seperate folder somewhere for app engine to access it or does it need to be in one single, messy file?
Check the app.yaml file, you have to edit it and add the folders.
Ex:
application: xxxx
version: 1
runtime: python
api_version: 1
handlers:
- url: /stylesheets
static_dir: resources/stylesheets
- url: /imgs
static_dir: resources/imgs
- url: /js
static_dir: resources/js
- url: /html
static_dir: resources/html
mime_type: text/html
- url: /.*
script: main.py
You have to put all your files that you want to display directly through an HTTP call in WEB-INF folder, assuming that you are coding in Java.

Google App Engine routing and pathing

I am looking to discover the best possible practice for building up a file tree inside a GAE/python.
It seems rather efficient to keep everything in one file and route everything there via WSGI.
Though for a complex and multifaceted site it makes sense to have distinct files serving different purposes.
I ran into some weird complications when I had many urls listed in the app.yaml
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /unit3.*
script: unit3.app
- url: /birthday.*
script: birthday.app
- url: /signup.*
script: signup.app
- url: /rot13.*
script: rot13.app
- url: /welcome.*
script: signup.app
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.1"
- name: jinja2
version: latest
and then having to duplicate those paths in separate .py files
app = webapp2.WSGIApplication([('/signup',SignUpHandler),
('/welcome',WelcomeHandler),
('/signup/.*', NotFoundPageHandler)]
,debug=True)
Is it weird that I think having to detail the routing of the url twice or more is cumbersome? Is there a way to have distinct files (html, css, py, js) and then have the app.yaml connect all the dots with the routing?
Best way to go is use webapp2 framework, routing is very simple there.
You can then just define urls.py and add routes there.
http://webapp-improved.appspot.com/
Routing in webapp.
http://webapp-improved.appspot.com/api/webapp2.html#uri-routing
Here is boilerplate code to get you started.
https://github.com/coto/gae-boilerplate

Static dir in app.yaml with space in dir name, how do I handle this?

I have a GAE + webapp2 app and i get this error for href line in my html,
INFO 2012-08-25 00:08:47,461 dev_appserver.py:2891] "GET /components%20copy_files/bootstrap-typeahead.js HTTP/1.1" 404 -
INFO 2012-08-25 00:08:47,470 dev_appserver.py:2891] "GET /components%20copy_files/application.js HTTP/1.1" 404 -
(I have a bunch of them but..)
The problem is my html is referencing to this folder for css/js
"components copy_files"
how do i map it in my app.yaml? I tried
- url: /components%20copy_files
static_dir: templates/components%20copy_files
and
- url: /components copy_files
static_dir: templates/components copy_files
and
- url: /components\%20copy_files
static_dir: templates/components\%20copy_files
But I can't get my site to load its css/js...? Thanks in advance for the help.
Also as a follow up question, if i'm porting html/css/js from a different hosting server and all the href links and dir are in place how do i get app.yaml/webapp2 to route to all those files.. do i have to declare every static dir in my app.yaml? btw: i'm porting a proj that uses twitter bootstrap (written by someone else) but i don't want to go back thru their code and edit all the hrefs, is there any quick solution to have these nested resource files play nicely with gae+app.yaml/webapp2?
Thanks a ton if you can help!!
The right configuration it's:
- url: /components%20copy_files
static_dir: templates/components copy_files
- url: /components%20copy_files
static_dir: you can have whatever name you want here(doesn't have to match the url)

Resources