Google App Engine: Disable favicon.ico - google-app-engine

I have a Google App Engine project running PHP 5.5. This is my app.yaml:
application: example
version: 1
runtime: php55
api_version: 1
threadsafe: true
handlers:
- url: .*
script: main.php
All requests go to main.php. My app only sends data for an Android application and thus doesn't need to display a favicon.ico. But if I call my application in my browser (Chrome) and consult the app logs afterwards there is a request to favicon.ico. How can I disable this or how can I tell App Engine to NOT SERVE a favicon?
EDIT: I can't just send some HTML to prevent the loading of the favicon, because I need to send JSON data to my application in which I can't include HTML.

Related

App Engine matching any "subdomain" to my service

I have a Strapi application on Google App Engine as the Default service.
The default URL App Engine generates is https://my-project.uc.r.appspot.com
When I create any other version for my default service or deploy another service, the new URLs would be something like: https://[identifier]-dot-my-project.uc.r.appspot.com
My problem is that if I replace [identifier] with anything at all it opens my Strapi Application root page.
I don't think this has anything to do with Strapi at all, it's probably a feature of App Engine.
My question is: How do I stop this from happening? I want only proper URLs to be matched. That is, if I create a "dev" version, I should be able to access it with the following URL: https://dev-dot-my-project.uc.r.appspot.com, but I don't want any other URL to be matched, like: https://12345-dot-my-project.uc.r.appspot.com
I am using a Standard Environment with the default app.yaml from Strapi docs
runtime: nodejs16
instance_class: F2
env_variables:
HOST: '0.0.0.0'
NODE_ENV: 'production'
DATABASE_NAME: 'strapi'
DATABASE_USER: 'postgres'
DATABASE_PASSWORD: '<password>'
INSTANCE_CONNECTION_NAME: '<instance_identifier>'
beta_settings:
cloud_sql_instances: '<instance_identifier>'
When the app is deployed to App Engine, the app.yaml is automatically modified to add some default params.
runtime: nodejs16
env: standard
instance_class: F2
handlers:
- url: .*
script: auto
I thought maybe this url: .* was the cause of this and tried to change it to url: /.* (Docs), but App Engine still add the url: .* again anyway at the end and it will have both handlers.
This is expected behavior. Per the documentation
If a request matches the PROJECT_ID.REGION_ID.r.appspot.com portion of the hostname, but includes a service, version, or instance name that does not exist, then the request is routed to the default service.
In your example, when you hit the url - https://12345-dot-my-project.uc.r.appspot.com and it turns out '12345' is not a valid version, the default service - https://my-project.uc.r.appspot.com will take over.
If you really want to block it, you'll have to write code to read the incoming url (i.e. the original url that came in), determine the version and if it's not in your list of versions, you raise an error (maybe return 404). This is basically what you'd do if you were offering a service built on GAE where each of your users had their own custom domain (version of your app) e.g. a blog hosting platform, an ecommerce site (like Shopify)

Next.js images return 500 error in production

I am deploying a Next.js app on GAE and none of the images in the public folder get served, they all return 500 with the following error after reviewing logs
EROFS: read-only file system, unlink '/workspace/.next/cache/images/zUb0XWtfOUy8jJS-olwIcsJpEse7wovGYRmT3B79mCc=/0.1641776976898.S-2U16B+8WquUZAAJsKsf1k9FpDiuBJX2T6gFU5eXy4=.svg
Here is how my app.yaml file looks like:
---
handlers:
- url: /.*
secure: always
script: auto
manual_scaling:
instances: 1
runtime: nodejs16
I run next build to get a production build, however none of the images load. Please help
It looks like GAE (Google App Engine) does not allow for writing, you can read them but its probably trying to perform some transcoding in the request, e.g: convert to svg
One potential way maybe to host the images in an external URL or use a host like imgix or cloudinary
https://nextjs.org/docs/api-reference/next/image#domains

Hosting pure angularjs app on google app engine

I have an angular js app with following structure
app structure
my app folder look like
app folder
the app does use any back end interaction for now but in future its gonna interact with a separate app engine java project . I want to host this angularjs app to google app engine but I am not able to understand the right configuration . I am more confused how do I set up the app.yaml for google app engine ... and is it necessary to have a main.py file as at present I do not have any handler
If I understand correctly, you would like to host a static web page on app engine, specifically an AngularJS app.
You don't need any server side code and can configure your app.yaml as follows:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /
static_files: www/index.html
upload: www/index.html
- url: /(.*)
static_files: www/\1
upload: www/(.*)
This is assuming you will host your client side code in a www folder and you use a index.html as your index file.
Also take a look at the following guide for hosting a static website [0].
[0] https://cloud.google.com/appengine/docs/standard/python/getting-started/hosting-a-static-website

Putting a Cloud Endpoints API in a separate App Engine module

I am developing an App Engine app and plan to also provide an API. I would like to separate this API from the main site, so I'm trying to use the "modules" feature to separate both apps. The main site would be the "default" module, and the API would lie in the "api" module. However, I'm having troubles with this.
Right now my main app's YAML file is like this:
application: my-app
module: default
runtime: python27
api_version: 1
...
handlers:
# Root handler
- url: /.*
script: main.app
secure: always
...
And the API module YAML file, like this:
application: my-app
module: api
runtime: python27
api_version: 1
handlers:
# Endpoints handler
- url: /_ah/spi/.*
script: api_main.app
secure: always
...
On the development server, the app is served on port 8000, and the API on port 7998.
With this configuration, my API doesn't work. Whenever I try to access it using localhost:7998/_ah/api/explorer, I don't get any result. If I try to run an API request manually, I get the following error: {"error": {"message": "BackendService.getApiConfigs Error"}}.
What's strange is I'm also seeing the following lines in the development server logs:
INFO 2014-06-15 18:00:32,368 module.py:639] default: "POST /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 500 -
INFO 2014-06-15 18:00:32,368 module.py:639] api: "GET /_ah/api/my-app/v1/events HTTP/1.1" 500 60
It seems like the API module is trying to POST data to the default module (as seen in the first line of logs).
Right now, the only workaround I found is to add the same handlers for /_ah/spi/.* in the default YAML file, but in this situation the separation between the main app and the API is not effective.
Can someone tell me if the configuration I'm trying to achieve is supported by Cloud Endpoints?
Thank you very much!
Same problem, I was able to make it work after may temptatives: the (only) way i found is to make the cloud endopoints module the default module. Then i have: on the dev server the two modules listening at different ports, you can see prot numbers on the log and on xxx.appspot.com: yourprojectid.appspot.com for the cloud endpoints and modulename-dot-yourprojectid.appspot.com for the other module
I had the same problem.
I solved using one file to publish my APIs. This file is indicated in app.yaml. I put my APIs in different files.
\
app.yaml
\apis
publish_api.py
\teacher
teacher_api.py
\student
student_api.py
**app.yaml:**
- url: /_ah/spi/.*
script: apis.publish_api.api
secure: always
**publish_api.py:**
import endpoints
from teacher.teacher_api import TeacherApi
from student.student_api import StudentApi
api = endpoints.api_server([TeacherApi, StudentApi])
**teacher_api.py:**
#endpoints.api( name='teacher',
version='v1',
allowed_client_ids=[WEB_CLIENT_ID, API_EXPLORER_CLIENT_ID],
scopes=[EMAIL_SCOPE])
class TeacherApi(remote.Service):
#endpoints.method(message_types.VoidMessage, StringMessage,
path='teacher', http_method='POST', name='writeTeacher')
**student_api.py:**
...
So, I get to mantain each file separately.

sitemap.xml on Google App Engine

I have the following yaml file for my Google App Engine website.
application: <my-app-id>
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /sitemap.xml
static_files: static/sitemap.xml
upload: static/sitemap.xml
- url: /
static_files: static/index.html
upload: static/index.html
- url: /
static_dir: static
When I test this app using the local server, the file sitemal.xml is accessible by navigating to.
http://localhost:8080/sitemap.xml
However, when I deploy the app, navigating to the following page just redirects me to index.html (it is impossible to download the xml file).
http://<my-domain>.net/sitemap.xml
http://www.<my-domain>.net/sitemap.xml
Why is the local version behaving differently from the deployed version? What can I do to make the file available in the deployed version?
Google App Engine doesn't support naked domains and most likely it's not being redirected correctly. Try accessing it via: http://www.<my-domain>.net/sitemap.xml to see if that works.
It turns out the problem was caused by domain redirection. If I access the application directly, via the following.
http://<app-id>.appspot.com/
Then everything is fine. Apparently something is broken in the way the domain hosting service handles the redirection.

Resources