can't access the index page with Google AppEngine - google-app-engine

When trying to visit the homepage of my website bob.com (just an example), I expect index.html to get displayed. Instead, I got a 404.
To reach index.html, I got to manually browse bob.com/index.html.
What did I do wrong with my current app.yaml ?
runtime: php
env: flex
runtime_config:
document_root: ./index.html
handlers:
# Handle the main page by serving the index page.
# Note the $ to specify the end of the path, since app.yaml does prefix matching.
- url: /*
static_files: index.html
upload: index.html

This has done the trick:
runtime: php
env: flex
runtime_config:
document_root: .
front_controller_file: index.html

Related

Unable to look up other files in appspot.com - problem with app.yaml

I have these files: index.php, filecallup.js, image.png, userprofile.php deployed in my xxx.appspot.com.
The index.php file is expected to collect some URL query variables and open the userprofile.php.
My problem is that when I click on the link (https://xxx.appspot.com/?user=peter) it still points to the index.php file and doesn't load userprofile.php.
I think it's a problem with my app.yaml file because it renders well in other servers except for GAE.
Here is the app.yaml code:
#Use the PHP 7.3 runtime (BETA) by replacing "php72" below with "php73"
runtime: php72
#entrypoint: serve main.php
service: default
#threadsafe: true
handlers:
# Serve a directory as a static resource.
#- url: /stylesheets
# static_dir: stylesheets
# Serve images as static resources.
- url: /(.+\.(gif|png|jpg))$
static_files: \1
upload: .+\.(gif|png|jpg)$
- url: /(.+\.(htm|html|css|js))$
static_files: \1
upload: .+\.(htm|html|css|js)$
# Serve your app through a front controller at index.php or public/index.php.
- url: /mail.php
script: auto
Here is the index.php code:
<?php
some codes here`
header('Location:userprofile.php')
>?

Vue production URL redirection returning 404 on gae

I have a vue application that I want to deploy to google app engine. I have deployed it and everything works as it should but when I manually enter in a url the app responds with a 404. Is there any way I can setup the app.yaml to allow for the redirection to the SPA from a url?
# GAE yml setup
runtime: python27
api_version: 1
threadsafe: true
# URL handlers
handlers:
- url: /
static_files: dist/index.html
upload: dist/index.html
- url: /(.*)
static_files: dist/\1
upload: dist/(.*)
- url: .*
static_files: dist/index.html
upload: dist/index.html
# GAE has a limit of 10,000 files so ignore node_modules and anything else thats not neccassary
skip_files:
- node_modules/
- .gitignore
- src/
- public/
- babel.config.js
- ^(.*/)?\..*$
How can I redirect with handlers to a specific page on the SPA?
Here is an example about what you are trying to achieve.
This specific solution (redirect all URLs to a single URL) works in two steps, modifying your app.yaml and adding some source in the .py file.
In the app.yaml, by adding the handlers: "App Engine can handle URLs by executing application code, or by serving static files uploaded with the code, such as images, CSS, or JavaScript."
handlers:
- url: /.*
script: main.py
And in the .py file, by adding the 'rule' to redirect.
class AllHandler(webapp.RequestHandler):
def get(self):
self.redirect("http://example.com", True)
application = webapp.WSGIApplication([('/.*', AllHandler)])

I am hosting my website (php files) in GAE. The app.yaml file is not routing the pages of my site. Error: No Found

My site has 8 pages and it is written in php: https://intercultural.appspot.com After deploying in GAE, it can load and dislpay the index.php page. However, does not display the other pages when I click on other links: Error: No Found The requested URL /file.php was not found on this server.
Here is the directory of my file: hightlighted in blue are the pages of my site.
enter image description here
Here is my app.yaml file:
runtime: php72 </b>
handlers:
# Serve a directory as a static resource.
- url: /styles
static_dir: styles
# Serve images as static resources.
- url: /(.+\.(gif|png|jpg))$
static_files: \1
upload: .+\.(gif|png|jpg)$
# Serve your app through a front controller at index.php or public/index.php.
- url: /(.+\.php)$
static_files: static/\1
upload: /(.+\.php)$
# I add the "/" to url bellow as suggested but still get same error
- url: /.*
script: auto
secure: always
Although it displays the site address in the browser, it says: Error: No Found The requested URL /file.php was not found on this server.
What is missing in the app.yaml file to route properly to the other pages of my site?
The URL for your final entry in the app.yaml should be url: /.* (with slash). This is necessary to match URLs of https://intercultural.appspot.com/*. You can see an example in the app.yaml reference.
I already fixed it.
The main problem was in the php version. I thought my code was written in php7.2 but actually it was php5.5, hence, the app.yaml didn't work properly.
Here is the app.yaml file:
This is my app.yaml file
runtime: php55
api_version: 1
handlers:
- url: /styles
static_dir: styles
- url: /(.+\.(gif|png|jpg))$
static_files: \1
upload: .+\.(gif|png|jpg)$
application_readable: true
- url: /
script: index.php
secure: always
- url: /(.+\.php)$
script: \1
secure: always

404 Error: unable to serve static content from static_dir

I'm unable to serve static content from static_dir (css). when I visited the URL http://srvc1.appeng-vj.appspot.com/styles/index.htmll I get 404 Page Not Found error... I had expected the static content, index.html, from static_dir css should have been served as per app.yaml handlers!
app.yaml as follows:
runtime: python
env: flex
runtime_config:
python_version: 3
handlers:
- url: /styles
static_dir: css
- url: /s1/
script: home.application
entrypoint: gunicorn -b :$PORT m1:application
service: srvc1
app root directory structure is as follows (attach screenshot)
Thanks for any clue what might be wrong here !
Serving static files with static_dir is a GAE-Standard capability. It's able to do that because it is VERY different from GAE-Flexibile (which you appear to be using).
See the GAE-Flexible doc for "Serving Static Files": it doesn't say anything at all about using static_dir. For GAE-Flexible, it says your options are "You can serve static content directly from your application, host it on Cloud Storage, or use a third-party content delivery network".

App engine App.yaml. what to include if I want to use a source php file?

I have a search.php file that is supposed to interact with my index.php file for autocomplete. The search.php file content Google Cloud SQL information. In my app.yaml, I have specify the env_variables for cloud SQL, but I am not sure what should I write in app.yaml for the search.php file.
My app.yaml is like:
runtime: php55
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: index.php
env_variables:
MYSQL_DSN: mysql:unix_socket=/cloudsql/myprojectexample:us-central1:product;dbname=pd
MYSQL_USER: root
MYSQL_PASSWORD: root
A part of my index.php: (just show you where the search.php going to be used)
<script>
$(function() {
$( "#456" ).autocomplete({
source: 'search.php',
minLength: 3
});
});
</script>
So, how should I include search.php in App.yaml to let it work? so far, the app engine won't interact with Cloud SQL.
thanks!
You can define a handler for your search.php file, and have your .* handler catch everything else. eg
runtime: php55
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /search.php
script: search.php
- url: .*
script: index.php
The handlers will be read in order until a match is found. So any time you try to call search.php it will point to your search.php file, and any time any other file is called it will point to index.php
You can also use the app.yaml file to organise your handlers or endpoints.
eg:
handlers:
- url: /api/search.php
script: search.php
- url: /api/authenticate.php
script: authenticate.php
You can also use this to remove the need for specifying the .php or file extension in the request.
handlers:
- url: /search/.*
script: search.php
Now anytime you call /search or yourappdomain.appspot.com/search you will hit the search page.
You can add as many handlers as you like, but remember they are searched in the order they are written, and as soon as a match is found the match will be executed. So have you catch-all handlers at the end!

Resources