I'm using webapp2 and python 2.7 on my app engine application. However, I'm having a problem with the url on app.yaml.
I have my static files inside a static/ directory, in the root of my path. So inside of static/ I have static/scripts/MyScript.js
When I set app.yaml like:
application: myapp
version: 1
runtime: python27
threadsafe: true
api_version: 1
handlers:
- url: /.*
script: myapp.app
- url: /static
static_dir: static
libraries:
- name: webapp2
version: latest
In my HTML code, the js is called like:
<script src="static/scripts/Fuel.js"></script>
But, the file is not loaded, and I get a 404 error. (This problem happens also for .css files.)
However if I change the first url in app.yaml to:
handlers:
- url: /
script: myapp.app
The static files are loaded, but when I try calling the routes url in my app, like an url I call in a form to save some data on server, this route is not found and I also get a 404 error.
Here is my routing code in myapp.py file.
app = webapp2.WSGIApplication(
[('/', MainHandler),
('/save', SaveData),],
debug=True)
So if I try to access myapp.appspot.com/save, it returns me a 404 error, saying:
The requested URL /save was not found on this server.
Any ideas? If you need more information about it, just ask on the comments.
Thanks.
Put your catch all url /.* at the bottom since this is evaluated in order. Meaning it never pass after that.
handlers:
- url: /static
static_dir: static
- url: /.*
script: myapp.app
Related
For each and every deploying our reactjs app on app engine, blank screen is displayed and We are receiving Static file referenced by handler not found: index.html as an error in the logs and after clearing the cache from browser side is resolving the above issue. Earlier we did not face this issue. Please refer the app.yaml file below
runtime: nodejs10
env_variables:
REACT_APP_ENV: "develope"
# service: ui
handlers:
- url: /static
static_dir: build/static
- url: /.*
secure: always
script: auto
You have to mention where is your index.html. On a full static react app, I have this app.yaml description
runtime: nodejs10
handlers:
- url: /
static_files: build/index.html
upload: build/index.html
- url: /
static_dir: build
I haven't backend. I don't know if you have one. Provide more precision on your service, I could help you to customize the deployment.
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
I made a website using Google app engine however, if I want to link from the main page to a different page in the folder structure, is does not load on the website.
The links are fine, they work if I check it on a browser directly from my drive. Do I need to put the entire folder in a seperate folder somewhere for app engine to access it or does it need to be in one single, messy file?
Check the app.yaml file, you have to edit it and add the folders.
Ex:
application: xxxx
version: 1
runtime: python
api_version: 1
handlers:
- url: /stylesheets
static_dir: resources/stylesheets
- url: /imgs
static_dir: resources/imgs
- url: /js
static_dir: resources/js
- url: /html
static_dir: resources/html
mime_type: text/html
- url: /.*
script: main.py
You have to put all your files that you want to display directly through an HTTP call in WEB-INF folder, assuming that you are coding in Java.
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.
How do I set index.html for the default root web page?
application: dfischerdna version: 1
runtime: python api_version: 1
handlers:
- url: /
static_dir: static_files
This works great when the visitor types
http://dfischerdna.appspot.com/index.html
However I would like that when he types this, the index.html web page would be displayed.
http://dfischerdna.appspot.com/ -> goes to 404 page
This might do the trick for you:
handlers:
- url: /
static_files: path/to/index.html
upload: local/path/to/index.html
- url: /(.+)
static_files: path/to/\1
upload: local/path/to/(.+)
The first url section will match the root URL and serve path/to/index.html. The second will match any path other than the root path, and will serve the file located under path/to that the request URI matches. For the URL http://yourapp.appspot.com/index.html it will serve path/to/index.html, and for a URL like http://yourapp.appspot.com/foo/bar.html it will serve path/to/foo/bar.html.
The upload directive tells GAE which local files to upload to serve as static files in your app instance.