GAE is not serving my robots.txt - google-app-engine

I have the following defined in my app.yaml:
handlers:
- url: /favicon.ico
static_files: img/favicon.ico
upload: noop
- url: /apple-touch-icon.png
static_files: img/apple-touch-icon.png
upload: noop
- url: /images
static_dir: img
- url: /robots.txt
static_files: media/robots.txt
upload: noop
- url: /humans.txt
static_files: media/humans.txt
upload: noop
There are other mappings after the declaration for /humans.txt but I'll remove them for brevity.
The noop directory is an empty directory.
However my browser gives me a 404 when I try to access these urls:
http://myapp.appspot.com/humans.txt
http://myapp.appspot.com/robots.txt
Why ?

Since you're using static files, upload should match the static_files location:
- url: /robots.txt
static_files: media/robots.txt
upload: media/robots.txt
- url: /humans.txt
static_files: media/humans.txt
upload: media/humans.txt

Related

why {app-url}/reset-password/{token} url showing page not found in react app deployed on google cloud where it working in local?

Token: {app-url}/reset-password/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MTI3OTUxNjksInVzZXJJZCI6NjB9.YS1seObMs45hcTDH4nSbTNh1W4fTTqPcpF4TUamfFFk
Error: Error: Not Found
The requested URL /reset-password/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MTI3OTUxNjksInVzZXJJZCI6NjB9.YS1seObMs45hcTDH4nSbTNh1W4fTTqPcpF4TUamfFFk was not found on this server.
Code:
<Route exact path="/reset-password/:token" component={ResetPassword} />
Does this issue bcs app deployed in GCloud or any thing needs to change in react code (project is create react app not webpack) ?
app.yaml
runtime: nodejs12
handlers:
- url: /(.*\..+)$
static_files: build/\1
upload: build/(.*\..+)$
- url: /.*
static_files: build/index.html
upload: build/index.html
Needs to change app.yaml
runtime: nodejs12
handlers:
- url: /static
static_dir: build/static
- url: /(.*\.(json|ico|js|png))$
static_files: build/\1
upload: build/.*\.(json|ico|js|png)$
- url: .*
static_files: build/index.html
upload: build/index.html
thanks to https://stackoverflow.com/a/55831186

Could not guess mimetype

On the test server goapp serv it works, on the appengine itself it get overwritten by application/octet-stream.
How can I tell appengine to stop doing that?
Could not guess mimetype for home/fonts/FontAwesome.otf. Using application/octet-stream...
My config file:
application: test
version: 0
runtime: go
api_version: go1
threadsafe: true
handlers:
- url: /home
static_dir: home
- url: /home/font/(.*\.woff)
static_files: home/font/\1
upload: home/font/(.*\.woff)
http_headers:
Content-Type: application/font-woff
- url: /home/font/(.*\.svg)
static_files: home/font/\1
upload: home/font/(.*\.svg)
http_headers:
Content-Type: image/svg+xml
- url: /home/font/(.*\.eot)
static_files: home/font/\1
upload: home/font/(.*\.eot)
http_headers:
Content-Type: application/vnd.ms-fontobject
- url: /home/font/(.*\.ttf)
static_files: home/font/\1
upload: home/font/(.*\.ttf)
http_headers:
Content-Type: application/x-font-ttf
- url: /home/font/(.*\.otf)
static_files: home/font/\1
upload: home/font/(.*\.otf)
http_headers:
Content-Type: application/x-font-otf
- url: /favicon.ico
static_files: home/favicon.ico
upload: home/favicon.ico
- url: /documentation
static_dir: documentation
- url: /.*
script: _go_app
inbound_services:
- warmup
I believe the reason it's working locally is that your system has the required mime type defined for the .otf extension in the /etc/mime.types or equivalent.
AppEngine probably doesn't have that. So you have to give it a hint about the correct MIME type. It looks like you're trying to do but, but you are using "http_headers". Try "mime_type" instead:
- url: /home/font/(.*\.otf)
static_files: home/font/\1
upload: home/font/(.*\.otf)
mime_type: application/x-font-otf
I hope that works for you. The documentation is at:
https://developers.google.com/appengine/docs/python/config/appconfig#Python_app_yaml_Static_file_handlers
It's also worth noting that generic rule should go last, like this:
handlers:
- url: /static/fonts/(.*\.otf)
static_files: static/fonts/\1
upload: static/fonts/(.*\.otf)
mime_type: application/x-font-otf
- url: /static/fonts/(.*\.ttf)
static_files: static/fonts/\1
upload: static/fonts/(.*\.ttf)
mime_type: application/x-font-ttf
- url: /static
static_dir: static

Google app engine + Go + serve static files + what is wrong with the config

I have this in app.yaml
application: test
version: 1
runtime: go
api_version: go1
handlers:
- url: /
static_files: client/index.html
upload: client/index.html
- url: /index\.html
static_files: client/index.html
upload: client/index.html
- url: /(.*\.(css|gif|png|jpg|ico|js|html))
static_files: client/\1
upload: client/(.*\.(css|gif|png|jpg|ico|js|html))
- url: /.*
script: _go_app
I start the app with "dev_appserver.py test".
When I open in the browser localhost:8080 or localhost:8080/index.html
I get a 404
application: test
version: 1
runtime: go
api_version: go1
handlers:
- url: /
static_files: app/client/index.html
upload: app/client/index.html
- url: /(.*\.(css|gif|png|jpg|ico|js|html))
static_files: app/client/\1
upload: app/client/(.*\.(css|gif|png|jpg|ico|js|html))
- url: /.*
script: _go_app

How to configure the app.yaml for using images?

i have a big problem with images for my project with python (appspots.com).
How to configure the app.yaml for images?
My Images are in the directory /css/images/xy.png
The log say:
INFO 2012-04-22 17:29:42,601 dev_appserver.py:2884] "GET
/css/images/ui-bg_glass_75_e6e6e6_1x400.png HTTP/1.1" 404 -
My app.yaml (only handlers):
- url: /js
static_dir: js
- url: /css/main.css
static_files: css/main.css
upload: css/main.css
- url: /css/jquery-ui-1.8.19.custom.css
static_files: css/jquery-ui-1.8.19.custom.css
upload: css/jquery-ui-1.8.19.custom.css
- url: .*
script: main.py
- url: /css/images/.*
static_dir: css/images
I hope that you can help me :)
The problem is that you have .* before /css/images./* and that pattern matches everything. Rearrange it like this:
- url: /js
static_dir: js
- url: /css/main.css
static_files: css/main.css
upload: css/main.css
- url: /css/jquery-ui-1.8.19.custom.css
static_files: css/jquery-ui-1.8.19.custom.css
upload: css/jquery-ui-1.8.19.custom.css
- url: /css/images
static_dir: css/images
- url: .*
script: main.py
EDIT:
Try removing the /.* from the end of the pattern, as illustrated above.

Serve static file using App Engine

I created an App Engine application. Till now, I only have a few HTML files to serve. What can I do to make App Engine serve the index.html file whenever someone visits http://example.appengine.com/ ?
Currently, my app.yaml file looks like this:
application: appname
version: 1
runtime: python
api_version: 1
handlers:
- url: /
static_dir: static_files
This should do what you need:
https://gist.github.com/873098
Explanation: In App Engine Python it's possible to use regular expressions as URL handlers in app.yaml and redirect all URLs to a hierarchy of static files.
Example app.yaml:
application: your-app-name-here
version: 1
runtime: python
api_version: 1
handlers:
- url: /(.*\.css)
mime_type: text/css
static_files: static/\1
upload: static/(.*\.css)
- url: /(.*\.html)
mime_type: text/html
static_files: static/\1
upload: static/(.*\.html)
- url: /(.*\.js)
mime_type: text/javascript
static_files: static/\1
upload: static/(.*\.js)
- url: /(.*\.txt)
mime_type: text/plain
static_files: static/\1
upload: static/(.*\.txt)
- url: /(.*\.xml)
mime_type: application/xml
static_files: static/\1
upload: static/(.*\.xml)
# image files
- url: /(.*\.(bmp|gif|ico|jpeg|jpg|png))
static_files: static/\1
upload: static/(.*\.(bmp|gif|ico|jpeg|jpg|png))
# index files
- url: /(.+)/
static_files: static/\1/index.html
upload: static/(.+)/index.html
# redirect to 'url + /index.html' url.
- url: /(.+)
static_files: static/redirector.html
upload: static/redirector.html
# site root
- url: /
static_files: static/index.html
upload: static/index.html
In order to handle requests to URLs that don't end with a recognized type (.html, .png, etc.) or / you need to redirect those requests to URL + / so the index.html for that directory is served. I don't know of a way to do this inside the app.yaml, so I added a javascript redirector. This could also be done with a tiny python handler.
redirector.html:
<!DOCTYPE html>
<html lang="en">
<head>
<script language="JavaScript">
self.location=self.location + "/";
</script>
</head>
<body>
</body>
</html>
If you're trying to map / to index.html:
handlers:
- url: /
upload: folderpath/index.html
static_files: folderpath/index.html
the url: will match on a path and supports regex.
- url: /images
static_dir: static_files/images
So if your image file is stored at static_files/images/picture.jpg use this:
<img src="/images/picture.jpg" />
It could be done using (app.yaml):
handlers:
- url: /appurl
script: myapp.app
- url: /(.+)
static_files: staticdir/\1
upload: staticdir/(.*)
- url: /
static_files: staticdir/index.html
upload: staticdir/index.html
Here is app.yaml for how I got a site generated by Jekyll to work:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /
static_files: _site/index.html
upload: _site/index.html
- url: /assets
static_dir: _site/assets
# index files
- url: /(.+)/
static_files: _site/\1/index.html
upload: _site/(.+)/index.html
- url: /(.*)
static_files: _site/\1
upload: _site/(.*)
- url: /.*
static_dir: _site
In WEB-INF/web.xml put:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

Resources