I am using Google Cloud Platform's PHP based static server. My public folder contains one landing page and and a web-app.
The landing page just is a static html file with few css and image files which resides on root.
The web-app is made of React, it's index.html resides inside the folder named app
I have configured my react app to use BrowserRouter.
The web-app returns 404 error when I refresh any page inside the app.
How to configure app.yaml to solve this. My current configuration is below:
runtime: php55
api_version: 1
threadsafe: true
skip_files:
- src/
- node_modules/
- ^(.*/)?app\.yaml
- ^(.*/)?gitlab\.yml
- ^(.*/)?app\.yaml
- ^package\.json
- ^package-lock\.json
- ^README\.md
- ^webpack.config\.js
- ^(.*/)?#.*#
- ^(.*/)?.*~
- ^(.*/)?.*\.py[co]
- ^(.*/)?.*/RCS/.*
- ^(.*/)?\..*
handlers:
- url: /
static_files: public/index.html
upload: public/index.html
secure: always
- url: /app/(.*\.(html|js|css))$
static_files: public/app/\1
upload: public/app/.*\.(html|js|css)$
secure: always
- url: /(.*)
static_files: public/\1
upload: public/(.*)
secure: always
I want to achieve something like nginx server's try_files option.
Related
I need to forward URLs, but the handlers in my app.yaml file are not accepting any configuration:
handlers:
- url: "/dashboard/([a-z])"
script: /admin/index.php?page=\1&token=xxx
- url: "/dashboard/login"
script: /admin/login.php?token=xxx
It only works if you access the full URL.
What's wrong?
So I am getting this when I try to deploy my app. Here are the files that make up my app:
main.py:
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write("<h1>Duracron!</h1>")
class EventHandler(webapp2.RequestHandler):
def get(self):
self.response.write("<h1>Duracsron!</h1>")
app = webapp2.WSGIApplication([
('/', MainHandler),
('/event/.*', EventHandler),
], debug=True)
app.yaml:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /.*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
- name: ssl
version: latest
cron.yaml:
cron:
- description: test task
url: /events/test
schedule: every 1 minutes
I can't seem to find out what's going wrong. From my understanding, the cron.yaml will make a request to the /events/test and app.yaml will redirect it to main.app and main.app routes it to EventsHandler(). What am I missing?
It looks like a typo in the word event which doesn't match events and that may be the cause of the problem. Try changing ('/event/.*', EventHandler), to ('/events/.*', EventHandler), so that it matches your cron.yaml
I was wondering how you can configure your app to restrict certain endpoints to logged in users or even admin users.
Here is my app.yaml
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: main.app
- url: /admin/.*
script: main.app
login: admin
However this doesn't work. When visiting any endpoint beginning with /admin/ I can simply access the url without logging in. Is there any configuration setting that I'm missing?
Atm, when trying to access
www.eyalw.com/1keyboard/
you get nothing,
but when accessing
www.eyalw.com/1keyboard
you get the correct page.
this is the current yaml:
application: eyalwcom
version: 1
runtime: python27
api_version: 1
threadsafe: no
handlers:
- url: /
static_files: static/index.html
upload: static/index.html
- url: /1keyboard
static_files: static/1keyboard.html
upload: static/1keyboard.html
- url: /
static_dir: static
libraries:
- name: webapp2
version: "2.5.2"
You can put in a regexp to match your url.
I'm not certain I can get the right regexp off the top of my head, I think it would be:
- url: /1keyboard/?
If you would like a trailing slash to always be added you can use a RedirectRoute from webapp2 with strict_slash=True, as described here: http://webapp-improved.appspot.com/api/webapp2_extras/routes.html#webapp2_extras.routes.RedirectRoute1
Instead of adding this to your app.yaml file you would include this where you defined the other routes and linked them to handlers.
I am running GoogleAppEngine (GAE) 1.6.3 with Python 2.7 and Django 1.3 by having:
libraries:
- name: django
version: "1.3"
in my app.yaml. The following should serve the admin media files at url /static/admin:
- url: /static/admin
static_dir: django/contrib/admin/media
expiration: '0'
But I get 404s for such admin media (css, etc). Am I using the correct location for the Django admin's media file?
The best way to do this is to copy or symlink the media directory into your app directory in your local files, so it is uploaded with your app's files. Then your app.yaml can refer to the relative path in the app directory.
There is a $PYTHON_LIB variable substitution you can use in app.yaml paths, but it looks like Django is not under $PYTHON_LIB in the live version of the Python 2.7 runtime.
When adding this to app.yaml
handlers:
- url: /static/admin
static_dir: static/admin
expiration: '0'
I was able to serve the CSS files by:
Adding this to settings.py:
BASE_DIR = os.path.abspath(os.path.dirname(__file__)) + os.sep
STATIC_ROOT = BASE_DIR + 'static'
And then running
python manage.py collectstatic
The admin media files appear correctly locally as well as on appspot.com.
The last command copies the media files into the the static/ directory. So in fact does what Dan Sanderson suggested but in a more automated way.
I tried Philipp Keller's collectstatic, but I don't have that command available.
So, add this handler to app.yaml:
- url: /static/admin
static_dir: django/contrib/admin/static/admin
expiration: '0'
then, in settings.py, delete ADMIN_MEDIA_PREFIX (removed in django 1.4) and add:
STATIC_URL = '/static/'
and you have working css.
is possible static file referenced by variable $PYTHON_LIB on deploy ??
file app.yaml
application: hello
version: 1
runtime: python27
api_version: 1
threadsafe: true
libraries:
- name: django
version: "1.3"
handlers:
- url: /admin/media
static_dir: $PYTHON_LIB/lib/django_1_3/django/contrib/admin/media
builtins:
- django_wsgi: on
log local:
INFO 2012-04-03 02:06:19,200 dev_appserver.py:2884] "GET /admin/media/css/base.css HTTP/1.1" 200 -
INFO 2012-04-03 02:06:19,207 dev_appserver.py:2884] "GET /admin/media/css/dashboard.css HTTP/1.1" 200 -
INFO 2012-04-03 02:06:19,242 dev_appserver.py:2884] "GET /admin/media/img/admin/default-bg.gif HTTP/1.1" 200 -
log error deploy app:
2012-04-02 19:17:32.775 /admin/media/css/dashboard.css 404 6ms 0kb
[02/Apr/2012:19:17:32 -0700] "GET /admin/media/css/dashboard.css HTTP/1.1" 404
Static file referenced by handler not found:$PYTHON_LIB/lib/django_1_3/django/contrib/admin/media/css/dashboard.css
Following seems to work fine for me.
app.yaml
handlers:
- url: /static
static_dir: staticfiles
settings
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
Run python manage.py collectstatic. Now under your staticfiles admin folder should be created.