Google app engine css not found/deployed - google-app-engine

I have the following app.yaml + file structure:
css files keep giving me 404:
I have tried different file structures and both static_dir and static_files in the app.yaml, nothing works...
ideas?

Based on the current file structure and your app.yaml config, your css files will have to be referenced in html relative to the url handler you defined: like /css/static.css.
With that covered, the static_dir has to be defined properly and relative to the location of your app.yaml, should be code/public/css and not /code/public/css. Note the leading slash you put there
handlers:
- url: /css
static_dir: code/public/css
If you want the full path though in your html, your config file will have to be tweaked slightly:
handlers:
- url: /code/public/css
static_dir: code/public/css

Related

React app giving 404 error when deployed to GCP

I have deployed my react app to GCP's App engine. It successfully deploys and the landing page is accessible. However none of the routes work. All the routes are giving '404' error.
I am pretty sure its the app.yaml configuration that has issue. Help please!
app.yaml
runtime: nodejs10
handlers:
- url: /
static_files: build/index.html
upload: build/index.html
- url: /
static_dir: build
The issue is that you are using both static_files and static_dir to your / url.
You need to either use static_files or static_dir.
From the description of your question it looks like you want to use static_dir to match everything that is inside the directory after the url: /.
As stated in the documentation:
static_dir: The path to the directory containing the static files, from the application root directory. Everything after the end of the matched url pattern is appended to static_dir to form the full path to the requested file.
static_files: A static file pattern handler associates a URL pattern with paths to static files uploaded with the application. The URL pattern regular expression can define regular expression groupings to be used in the construction of the file path. You can use this instead of static_dir to map to specific files in a directory structure without mapping the entire directory.

Google App Engine URL Routing with App.Yaml for Static resource and Script

I am busy migrating a app into the GAE. I used to utilize timthumb.php to resize images on demand from within a static img folder. From the same folder I used to serve static images aswel.
eg: example.com/img/image_name.jpg
example.com/img/timbthumb.php?src=example.com/img/image_name.jpg&w=50&h=50
etc.
I am not using timbthump.php anymore, I have re-written it to serve images via CloudStorageTools.php api, and I do not want to go through all code to rewrite the image paths.
Now, on my local environment the google app engine is serving both versions of images, static and dynamic via timbthumb.php.
On the live environment GAE only serves static or dynamic, I cannot build URL handlers to serve both.
The timbthumb.php images are throwing a 404 error with both handlers.
My app.yaml
application: my-app
version: 1
runtime: php55
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /css
static_dir: dir/css
#timbthumb.php images
- url: /img/(.+\.php)$
script: dir/img/timbthumb.php
#static images
- url: /img
static_dir: dir/img
#all other php files
- url: /.*
script: dir/index.php
My Question, how can I make GAE route static images via example.com/img/ and the timthumb.php script located at example.com/img/timbthumb.php in my app.yaml?
Thanks
According to the documentation you can't serve a script from a static directory:
A static directory handler makes it easy to serve the entire contents
of a directory as static files. Each file is served using the MIME
type that corresponds with its filename extension unless overridden by
the directory's mime_type setting. All of the files in the given
directory are uploaded as static files, and none of them can be run
as scripts.
The fact that it appears to be running in the development server is just another reflection of the fact that the development server is just an approximation of GAE, but not really GAE.
If your image paths naming allows it you could use static_files routing rules instead of a static_dir one:
A static file pattern handler associates a URL pattern with paths to
static files uploaded with the application. The URL pattern regular
expression can define regular expression groupings to be used in the
construction of the file path. You can use this instead of
static_dir to map to specific files in a directory structure without
mapping the entire directory.

app.yaml cannot call my css file for my index.php

I have create an app in php. The folder "myapp-test-1" has a file called index.php and a folder CSS which includes the file main.css which is the css file for index.php .I am trying to create my app yaml file in order to upload my project in google's app engine. This is my app.yaml file:
application: myapp-test-1
version: 1
runtime: php
api_version: 1
handlers:
- url: /.*
script: index.php
- url: /css
static_dir: css
- url: /css/
script: main.css
when test it in browser it seems that index.php file is not full loaded. Moreover the css for index.php is not working.
You need to have the
- url: /.*
script: index.php
last, because if you have it first, the order in which GAE will read this file is this, then the other two css ones. The regex .* next to url says that all URLs will lead to index.php, so putting this last will allow GAE to read the css ones first. You also don't need to include
- url: /css/
script: main.css
if you're only going to load the css files in your index.php.
So overall, it should look like
application: myapp-test-1
version: 1
runtime: php
api_version: 1
handlers:
- url: /css
static_dir: css
- url: /.*
script: index.php
I believe that you should try to leave only :
- url: /.*
script: path/index.php
and remove the two references to the css.
from inside the index.php, make sure that you call your css file using the right path.
eventually if you use firefox, the function "inspect element" and the console, will tell you why your file is not loaded...
good luck

Moving HTML files to their own directory in Google App Engine (Using Jinja2 Templates) - Error 13

This seems like its probably something simple and n00bish, but I can't move my .html files to their own directory without the site coming to a screaming halt. They work file if left in the root folder.
Here's what I tried to do
<root>
|_ app.yaml
|_ main.py
|_ ...etc
|_<layout>
|_ base.html
|_ home.html
|_ ...etc
I added the following to my app.yaml file:
- url: /layout
static_dir: layout
I figured that would do it, and since nothing else uses that directory I assume the order in HANDLERS doesn't matter. Here is my complete handlers section in case someone spots something obvious I missed (I admit to not having a great understanding of this, despite having trolled through documentation and other problems here relating to static files and directories):
handlers:
- url: /favicon.ico
static_files: favicon.ico
upload: favicon.ico
- url: /layout
static_dir: layout
- url: /stylesheets
static_dir: stylesheets
- url: .*
script: main.app
I've tried mixing up the order of the handlers, but the error is always the same:
IOError: [Errno 13] file not accessible: 'E:\\Users\\Steve\\Documents\\test_gae\\test\\layout\\home.html'
Any suggestions would be greatly appreciated, Cheers
ANSWER, as per the answer from voscausa: these HTML files are templates, not static pages. Removing the static handler for 'layout' completely solved the problem.
If you use Jinja2, you do not need to put the /layout folder in your app.yaml, because you do not serve the templates static, but you render the templates with jinja and write the response HTML.
So the problem must be in your code. Look at the template path.
The order of handler matters. The url patterns are matched from top to bottom. This means
- url: /.*
script: main.app
is always the last handler!!

Google AppEngine app.yaml error 500

I'm having problems getting my assets folder to upload to the root, but also allowing a custom url handler /cron to upload too.
application: appname
version: 1
runtime: python
api_version: 1
handlers:
- url: /cron
script: assets/backup/main.py
- url: /
static_files: assets/index.html
upload: assets/index.html
- url: /
static_dir: assets
As you can see, my backup script is also located in my assets or static folder. If I remove my static_dir: assets handler, my /cron handler works fine.
I also tried changing the url to /assets to see if I could overwrite it that way.
Any idea why this happens and how I can fix it?
You are defining the whole assets directory as static with static_dir: assets. You can't run any script inside a static_dir. The fix is to move assets/backup/main.py to outside the directory defined as static_dir.

Resources