Google App Engine ignores context path - google-app-engine

I have the following context path handlers in my app.yaml:
runtime: nodejs
env: flex
resources:
cpu: 1
memory_gb: 1
disk_size_gb: 20
handlers:
- url: /api
secure: always
script: app.js
- url: /
secure: always
static_dir: public
Static works OK. There are two problems i have:
secure: always
pragma does not work as expected. There's no redirect from http to https.
Second, i have /test endpoint in my NodeJS app. However /api/test is 404, but /test works, ignoring /api.
What am I doing wrong?
Generated runtime config:
runtime: nodejs
api_version: '1.0'
env: flexible
threadsafe: true
handlers:
- url: /api
script: app.js
secure: always
- url: '/(.*)'
secure: always
application_readable: false
static_files: "public/\\1"
require_matching_file: false
upload: 'public/.*'
automatic_scaling:
min_num_instances: 2
max_num_instances: 20
cpu_utilization:
target_utilization: 0.5
resources:
cpu: 1
memory_gb: 1
disk_size_gb: 20

As stated in this answer, the flex environment doesn't support the handlers section in app.yaml. That post also has a couple of examples of how to get this up and running in nodejs.
The second half of your question has a similar answer - you need to implement these redirects in your node app directly.

Related

Why does Google App Engine Standard Edition for Java create a __static__ folder and double the number of files deployed to a project?

I am deploying a web application to Google App Engine Standard edition using Java 8.
It is a documentation web site plus servlets that includes a huge amount of static web content (built with Jekyll).
I recently started getting this error trying to deploy the app:
ERROR: (gcloud.app.deploy) INVALID_ARGUMENT: This deployment has too many files.
New versions are limited to 10000 files for this app.
- '#type': type.googleapis.com/google.rpc.BadRequest
fieldViolations:
- description: This deployment has too many files.
New versions are limited to 10000 files for this app.
field: version.deployment.files[...]
My src/main/webapp folder has 5016 files.
But after running:
mvn clean install appengine:stage
my target/appengine-staging folder has 10113 files.
I see that the files are in 2 locations, both
target/appengine-staging
and
target/appengine-staging/__static__
Why do they appear twice?
Is this normal?
Or am I doing something wrong?
How can I avoid this duplication?
Or do I have to limit my files to under 5000?
Thanks for any advice.
Note: The generated app.yaml looks like this:
runtime: java8
instance_class: F1
inbound_services:
- warmup
derived_file_type:
- java_precompiled
threadsafe: True
auto_id_policy: default
beta_settings:
'source_reference': 'https://...'
api_version: 'user_defined'
handlers:
- url: (/.*/)
static_files: __static__\1index.html
upload: __NOT_USED__
require_matching_file: True
login: optional
secure: always
- url: (/)
static_files: __static__\1index.html
upload: __NOT_USED__
require_matching_file: True
login: optional
secure: always
- url: (/.*)
static_files: __static__\1
upload: __NOT_USED__
require_matching_file: True
login: optional
secure: always
- url: /.*
script: unused
login: optional
secure: always
skip_files: app.yaml

What is the solution for the error when I deploy pubsub for PHP with App Engine?

I was working on google Pubsub with App Engine, to get notifications from google play about InApp subscriptions status.
When I deploy my app with the command "gcloud app deploy", error message comes:
ERROR: (gcloud.app.deploy) An error occurred while parsing file: [/home/testaccount/php-docs-samples/pubsub/app/app.yaml]
Unable to assign value 'pubsub.js' to attribute 'url':
Value 'pubsub.js' for url does not match expression '^(?:(?!^)/.|..|((.).*(?!$).)$'
in "/home/testaccount/php-docs-samples/pubsub/app/app.yaml", line 6, column 8
My app.yaml file:
runtime: php55
api_version: 1
threadsafe: true
handlers:
- url: pubsub.js
static_files: pubsub.js
- url: /.*
script: index.php
env_variables:
GOOGLE_PROJECT_ID: "testproject"
I have followed the insturctions in the linl:
Writing and Responding to Pub/Sub Messages
I did not modify app.yaml file, I do not know what is going on? I tried to deploy "Hello, World!" for PHP on App Engine" exmaple and it worked.
Please help me to solve it.
url should start with a slash. Try:
- url: /pubsub.js
static_files: pubsub.js
After a week searching about why I get HTTP error 500 (Internal Server Error) when I browse https://testproject.uc.r.appspot.com/, I got the reason, it was from app.yaml file, all errors came from php version.
Old app.yaml:
runtime: php55
api_version: 1
threadsafe: true
handlers:
- url: /pubsub.js
static_files: pubsub.js
upload: pubsub.js
- url: /.*
script: index.php
env_variables:
GOOGLE_PROJECT_ID: "testproject"
New app.yaml:
runtime: php72
handlers:
- url: /pubsub.js
static_files: pubsub.js
upload: pubsub.js
- url: /.*
script: auto
env_variables:
GOOGLE_PROJECT_ID: "testproject"
Thank God.

Access static json file in google app engine 2.7 standard environment - IOError(2, 'No such file or directory')

We are trying to access .json file inside our python code in Google App Engine.
Here is our app.yaml
service: worker
instance_class: F2
runtime: python27
api_version: 1
threadsafe: true
automatic_scaling:
max_instances: 100
min_pending_latency: 200ms # default value
max_pending_latency: automatic
handlers:
- url: /stylesheets
static_dir: stylesheets
- url: /images
static_dir: images
- url: /javascripts
static_dir: javascripts
- url: /(.*\.(gif|png|jpg|json))$
static_files: static/\1
upload: static/.*\.(gif|png|jpg|json)$
application_readable: true
- url: /static
static_dir: static
application_readable: true
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /.*
script: worker.app
login: admin
libraries:
- name: webapp2
version: "2.5.2"
- name: jinja2
version: latest
We are using it in our application like this.
path = os.path.join(os.path.dirname(__file__)[0], '/static/google_web_app_script_credentials.json')
flow = InstalledAppFlow.from_client_secrets_file(path,self.GOOGLESHEETS_SCOPES )
But we are receiving the error.
IOError(2, 'No such file or directory')
We have tried various options of changing path including path = os.path.join(os.path.dirname(file)[0], '../static/google_web_app_script_credentials.json')
When we go to the GCP console -> Debug and review the current code we are able to see the .json file under static folder. This means that the file is there, we are not able to get the application to read it. This service is as "worker".
From your App Engine app, you don't have access to your static files. Move the file to another location within your project, and you will then be able to access it.
Even more importantly, you don't want to store credentials in your static folder! Anyone on the web will be able to access them via the URL!

Use of gcloud app deploy using sdk always results in error

I am using the following app.yaml. I am trying to deploy my angular app. Tried to use 3 different variants of the sdk but everytime it throws an error. - 218 -201- 215
runtime: custom
env: flex
threadsafe: true
automatic_scaling:
min_num_instances: 1
max_num_instances: 10
cool_down_period_sec: 120 # default value
skip_files:
- ^(.*\/)?.*\.py[co]$
- ^(.*\/)?.*\.py$
- ^(.*\/)?.*/RCS/.*$
- ^.git(.*\/)?
- ^(.*/)?.*\.bak$
- ^(.*)?\/?src[\/]?(?:(.*)?[\/]?)$
- ^[\.]?ssl(.*[\/]?)?$
- ^[\.]?idea(.*[\/]?)?$
- ^[\.]?e2e(.*[\/]?)?$
handlers:
- url: /
static_files: dist/index.html
upload: dist/index.html
application_readable: true
- url: /
static_dir: dist
application_readable: true
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
application_readable: true
- url: /(.+\.(gif|png|jpg|js|css|json|woff2|svg|ttf|eot|woff))$
static_files: \1
upload: .+\.(gif|png|jpg|js|css|json|woff2|svg|ttf|eot|woff)$
application_readable: true
But I am always ending up with the error
gcloud components update --version 185.0.0
ERROR: gcloud crashed (TypeError): unsupported operand type(s) for
+=: 'int' and 'NoneType'
If you would like to report this issue, please run the following
command:
gcloud feedback
To check gcloud for common problems, please run the following
command:
gcloud info --run-diagnostics
Could someone guide me with this?
Note: I was able to deploy successfully a couple of days ago with the version - 201.
I am unsure as to why . I am everybit confused as well. I removed all the comments I had for "skip_files" section and then it allowed me deploy without any errors
api_version: 1
runtime: python
env: flex
threadsafe: yes
readiness_check:
check_interval_sec: 120
timeout_sec: 40
failure_threshold: 5
success_threshold: 5
app_start_timeout_sec: 1500
skip_files:
- ^(.*/)?#.*#$
- ^(.*/)?.*~$
- ^(.*/)?.*\.py[co]$
- ^(.*/)?.*/RCS/.*$
- ^(.*/)?\..*$
- ^(.*/)?.*\.bak$
- ^(.*/)?.*\.yaml$
- ^node_modules/(.*/)?
- ^src/(.*/)?
handlers:
- url: /
static_files: dist/index.html
upload: dist/index.html
- url: /
static_dir: dist

main domain + subdomain + CSS not found

I have one dispatch.yaml that splits 2 services; admin_main.py that controls the admin login, and main.py that controls the user landing. My problem is that admin_main.py does not see its own CSS that I directed it to it. However, it keeps matching with the main.py CSS.
my files are structured as
admin
|assets
|CSS
+styles.min.css
www
|assets
|CSS
+styles.min.css
dispatch.yaml:
dispatch:
# Default service serves simple hostname request.
- url: "example.net/"
service: default
# Default service serves simple hostname request.
- url: "app-example.appspot.com/"
service: default
# Default service serves simple hostname request.
- url: "admin.example.net/"
service: admin
- url: "admin-dot-app-example.appspot.com/"
service: admin
admin_main.py:
service: admin
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /assets/css/styles.min.css
static_files: admin/assets/css/styles.min.css
upload: admin/assets/css/styles.min.css
- url: /.*
script: subdomain.app
libraries:
- name: webapp2
version: latest
- name: jinja2
version: latest
main.py:
service: default
runtime: python27
api_version: 1
threadsafe: yes
default_expiration: "4d 5h"
handlers:
- url: /assets/css
static_dir: www/assets/css
- url: /assets/img
static_dir: www/assets/img
- url: /.*
script: main.app
libraries:
- name: webapp2
version: latest
- name: jinja2
version: latest
in the .html the links to the CSS are
<link rel="stylesheet" href="assets/css/styles.min.css">
for both landing sites. But that shouldn't be a problem since the dispatch.yaml separate the incoming calls, right?
I'm not really sure what is causing the problem. Also, I'm new to yaml and I been reading it's documentation.
One solution for this is to store every CSS in the same file, and give them different names. Then in app.yaml in the handlers section add this:
- url: "/assets/css/(.*\\.(css))$"
static_files: {CSS_DIR_IN_PROJECT}/\1
upload: {CSS_DIR_IN_PROJECT}/.*\.(css)$
application_readable: true
that was my only way of solving the problem

Resources