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.
Related
I am trying to set up a vue.js application with the vue router set in "history" mode. I also want to serve my back end APIs from the same app engine application. (e.g., if a user navigates to /some/path/in/the/app and refreshes the page or shares the link, the application will display the expected page)
here is my app.yaml:
runtime: python37
handlers:
- url: /api/.*
secure: always
script: auto
- url: /css
static_dir: www/css
- url: /js
static_dir: www/js
- url: /semantic
static_dir: www/semantic
- url: /img
static_dir: www/img
- url: /
static_files: www/index.html
upload: www/index.html
- url: /.*
static_files: www/index.html
upload: www/index.html
When I try to hit any of my api endpoints, the static index.html file is served instead of the response from the endpoint.
If the last route is omitted (url: /.*), then the api endpoints are served correctly, but the Vue.js app can only be entered from the "/" route and the deep links in the application do not work as expected
I am not looking to have a script in my application to serve the a static file.
note, this question is similar, but none of the answers addressed my situation:
AppEngine app.yaml config for single page apps
The trick was to follow a microservice architecture and split my application into two modules and define the routes in a dispatch.yaml file.
There is a sample project here:
App Engine Modules sample project
I am fairly new to Google App Engine. When I keep files in images folder and run bat file, it uploads images properly but when I remove those images and put new images to upload, it removes previous images.
My app.yaml looks like this
application: testcdn
version: 1
runtime: python27
api_version: 1
threadsafe: true
default_expiration: "1d 1h"
handlers:
- url: /css
static_dir: css
- url: /images
static_dir: images
- url: /js
static_dir: js
- url: /.*
static_files: index.html
upload: index.html
Also when 2 developers try to upload images to the same cdn store with different google accounts, it removes images previously uploaded by other developer.
Please suggest.
Your local files mirror your deployed files. If you remove files locally, then deploy, the remote files will be deleted. You are not just defining the files to upload, but the files to mirror remotely.
I am not sure about your 2nd comment. Do the files have the same filenames? You will have to provide the upload code for diagnosis.
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
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.