Default document in Google App Engine - google-app-engine

Is it possible to specify the equivalent of a default document for directories in Google App Engine so that navigating to that directory automatically redirects to its index.html for example, if it contains one?
If I have this in my app.yaml:
- url: /demos
static_dir: demos
and the demos directory contains an index.html page, how can I tell App Engine to automatically redirect to that page?

App Engine uses regular expression matches on the request path to determine what script to call or document to serve. If you just have the one index document, you can do it like this:
- url: /demos/
static_files: demos/index.html
upload: demos/index\.html
More generally, you can define static files for paths ending in slashes ('directories') like this:
- url: /(.*)/
static_files: \1/index.html
upload: .*/index\.html

I got this to work by using this in my yaml.
- url: /(.+)
static_files: static/\1
upload: static/(.+)
- url: /
static_files: static/index.html
upload: static/index.html
Replace static with demos and you should be set. It redirects the blank domain to index.html and al others to the static folder.

For GAE/J, add the following to your web.xml file.
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
www.example.com/test/ will now serve www.example.com/test/index.html

- url: /demos(/.+|)/
static_files: demos\1/index.html
upload: demos/(.+/|)index\.html
- url: /demos/
static_dir: demos

Related

docusaurus links on google app engine give SEO problems

I have set up a website using docusaurus which works great, but when I check the indexing status of my website on google, I got a lot of 'Discovered - currently not indexed' problems, which appears to be a routing problem.
The compiled version of the docusaurus website generates an 'index.html' file for every page or md file in the docusauus project in a separate folder, but the generated links don't add the 'index.html' and instead end like this: https://cam-inspector.com/contact. The browser doesn't seem to go to 'https://cam-inspector.com/contact/index.html', instead it uses the root index.html page and appears to handle the routing locally. This works for viewing, but the google crawler only gets to see the root, so every page contains a canonical url of 'https://cam-inspector.com'. When you browse directly to 'https://cam-inspector.com/contact/index.html', the correct file is retrieved from the server and the canonical tag is correct to 'https://cam-inspector.com/contact'.
I tried to add a redirect to the yaml file of the google app engine deployment so that it would add 'index.hmtl' to all routes that don't end with a file extension, but that doesn't seem to work:
handlers:
# for url without extensions, needs to go to index.html to get seo correct
- url: /(?:/|^)[^./]+$
static_files: www/\1/index.html
upload: www/(.*)/index.html
# files with extension, needed to get all the files
- url: /(.*\..+)$
static_files: www/\1
upload: www/(.*\..+)$
# Catch all handler to index.html, needed to get the root
- url: /.*
static_files: www/index.html
upload: www/index.html
In this post: app.yaml : Redirect any URL ending with / to {url}/index.html they appear to say that you can't add a redirect like that to the yaml def.
So now I'm a little stuck, the only thing I can think of is to add '/index.html' to all the links in the docusaurus code, but that sort of creates something very difficult and tricky to maintain (especially with the auto generated side bar of the docs, where it's much harder to change the links).
Any ideas on how to fix this?
found the solution:
use the following config in docusaurs.config.js: trailingSlash: true,
use these handlers in app.yaml:
- url: /
static_files: www/index.html
upload: www/index.html
- url: /(.*)/$
static_files: www/\1/index.html
upload: www/(.*)
- url: /(.*)
static_files: www/\1
upload: www/(.*)
make certain you declare the links to your pages this way: \contacts\
then things start to behave as expected.
Here's my version of deploying a Docusaurus site to Google App Engine.
handlers:
# static files with a URL ending with a file extension
# (e.g. favicon.ico, manifest.json, jylade.png)
- url: /(.*\..+)$
static_files: build/\1
upload: build/(.*\..+)$
# index page
- url: /
static_files: build/index.html
upload: build/index.html
# anything that ends with a slash (e.g. /docs/)
- url: /(.*)/$
static_files: build/\1/index.html
upload: build/(.*)
# anything else (e.g. /docs)
- url: /(.*)
static_files: build/\1/index.html
upload: build/(.*)
Works for me with the default Docusaurus configuration.
It does not require trailingSlash: true.

Issue with app.yaml to deploy static website on App Engine, images won't display

I'm trying to deploy my web app on Google App Engine.
My project follows this structure
The app.yaml has this content:
runtime: nodejs14
handlers:
- url: /
static_files: www/index.html
upload: www/index.html
- url: /(.*)
static_files: \1
upload: (.*)
But, when I execute gcloud app deploy --project=MY PROJECT, and open my site, it looks like this:
I assume there is an error in the app.yaml file, but I don't understand what. Any ideas?
Update your second URL handler to:
- url: /(.*\.(svg|png))$
static_files: www/images/\1
upload: www/images/.*\.(svg|png)$
Then reference your img src like this:
<img src="/test.png" alt="oops" width="104" height="142">
One thing to add, you can also use static_dir as your second URL handler instead. This way it's easier organize static files per directory. Change your app.yaml to:
runtime: nodejs14
handlers:
- url: /
static_files: www/index.html
upload: www/index.html
- url: /static-img
static_dir: www/images
In that example, what happens is that images located at www/images are mapped on URLs beginning at /static-img. You can use that URL to reference your img src in your HTML. For example:
<img src="/static-img/test.png" alt="oops" width="104" height="142">
Learn more at: https://cloud.google.com/appengine/docs/standard/nodejs/config/appref#handlers_static_dir

I am hosting my website (php files) in GAE. The app.yaml file is not routing the pages of my site. Error: No Found

My site has 8 pages and it is written in php: https://intercultural.appspot.com After deploying in GAE, it can load and dislpay the index.php page. However, does not display the other pages when I click on other links: Error: No Found The requested URL /file.php was not found on this server.
Here is the directory of my file: hightlighted in blue are the pages of my site.
enter image description here
Here is my app.yaml file:
runtime: php72 </b>
handlers:
# Serve a directory as a static resource.
- url: /styles
static_dir: styles
# Serve images as static resources.
- url: /(.+\.(gif|png|jpg))$
static_files: \1
upload: .+\.(gif|png|jpg)$
# Serve your app through a front controller at index.php or public/index.php.
- url: /(.+\.php)$
static_files: static/\1
upload: /(.+\.php)$
# I add the "/" to url bellow as suggested but still get same error
- url: /.*
script: auto
secure: always
Although it displays the site address in the browser, it says: Error: No Found The requested URL /file.php was not found on this server.
What is missing in the app.yaml file to route properly to the other pages of my site?
The URL for your final entry in the app.yaml should be url: /.* (with slash). This is necessary to match URLs of https://intercultural.appspot.com/*. You can see an example in the app.yaml reference.
I already fixed it.
The main problem was in the php version. I thought my code was written in php7.2 but actually it was php5.5, hence, the app.yaml didn't work properly.
Here is the app.yaml file:
This is my app.yaml file
runtime: php55
api_version: 1
handlers:
- url: /styles
static_dir: styles
- url: /(.+\.(gif|png|jpg))$
static_files: \1
upload: .+\.(gif|png|jpg)$
application_readable: true
- url: /
script: index.php
secure: always
- url: /(.+\.php)$
script: \1
secure: always

Upload attribute Google App Engine - app.yaml

I'm redirecting everything to a single file in my app.yaml like so
- url: /.*
script: frontcontroller.application
but I still have to use robots.txt, which causes an error when I do
- url: /robots.txt
static_files: robots.txt
- url: /.*
script: frontcontroller.application
the error is " missing "upload" attribute for URL robots.txt, I understand that it requires a third option like so
- url: robots.txt
static_files: robots.txt
upload: ??????
what would the proper value be for the upload attribute?
You should include the actual path to the file that you want to upload, which in your case is the robots.txt:
- url: robots.txt
static_files: robots.txt
upload: robots.txt
For more read the: Python Application Configuration.
Here's how I understand it:
static_file field let you specify the mapping used to serve the static file request.
upload field is used to distinguish between script file and a static file.

favicon.ico "not found error" in App Engine

I am trying to develop on Google App Engine and in the list of the errors displayed in the admin console I always see the following:
/favicon.ico
i read the documentation , added a new folder called static and added this in my app.yaml:
- url: /favicon.ico
static_files: static/favicon.ico
upload: static/favicon.ico
but even now I'm getting the same error...
This entry should be placed before the entry for the main handler, like:
- url: /favicon.ico
static_files: media/img/favicon.ico
upload: media/img/favicon.ico
- url: /robots.txt
static_files: media/robots.txt
upload: media/robots.txt
- url: .*
script: main.py
The entries are processed in order of apperance and first one that matches wins.
If you are doing this in Java, I got rid of the error by putting a blank "favicon.ico" file in the "war" directory.
If you want to make your own quick and ugly "favicon.ico" file, this website was super easy to use: http://www.favicon.cc/
For your application, favicon.ico should be a static image. You can upload a favicon.ico file with your application, and in your app.yaml file configure your application to serve the image when the url /favicon.ico is requested. Below is an example entry in your app.yaml file for /favicon.ico. We assume you include the favicon.ico file in the directory path static/images:
- url: /favicon.ico
static_files: static/images/favicon.ico
upload: static/images/favicon.ico
is written here
I am using this snippet in a GAE app configuration:
handlers:
- url: /(.*\.(ico|png|webmanifest))$
static_files: faviconfiles/\1
upload: faviconfiles/.*\.(ico|png|webmanifest)$
I then put the corresponding set of files (these days if you seriously want to set a "favicon" it's a set of files incl. e.g. apple-touch-icon.png) into the ./faviconfiles directory next to my app.yaml.

Resources