Appengine module: Routing with dispatch.yaml not working

烈酒焚心 提交于 2020-01-15 07:18:53

问题


I'm using modules, but i cannot put to work the routing as explanined here https://developers.google.com/appengine/docs/python/modules/routing

to update:

appcfg.py update dispatch.yaml app.yaml comunapp_site.yaml

appcfg.py update_dispatch

the endpoint api works as expected but the site doesn't i expected this to work

https://skilled-cargo-111.appspot.com/comunapp/

but only this works

https://comunapp-dot-skilled-cargo-111.appspot.com/

Here are my yaml file:

app.yaml

application: skilled-cargo-111
module: default
version: 1
runtime: python27
api_version: 1
threadsafe: yes    

automatic_scaling:
  min_idle_instances: 1
  max_pending_latency: 3s    

handlers:
- url: /_ah/spi/.*
  script: mobile_api.application   

libraries:
- name: endpoints
  version: 1.0

comunapp_site.yaml

application: skilled-cargo-111
module: comunapp
version: 1
runtime: python27
api_version: 1
threadsafe: yes

automatic_scaling:
  min_idle_instances: 1
  max_pending_latency: 10s

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: /css
  static_dir: css

- url: /bootstrap
  static_dir: bootstrap

- url: /images
  static_dir: images

- url: /javascript
  static_dir: javascript


#- url: /login.*
#  script: "main.py"
#  secure: always

- url: /.*
  script: comunapp_site.app
  login: optional
  secure: always

libraries:
- name: webapp2
  version: "2.5.2"
- name: jinja2
  version: latest

dispatch.yaml

application: skilled-cargo-111

dispatch:
  - url: "*/favicon.ico"
    module: default

  - url: "*/comunapp/*"
    module: comunapp

  - url: "*/api/*"
    module: default

回答1:


What's happening is that your dispatch file says to route any request coming to hostname/comunapp/* to your comunapp handler, but the URL getting to that handler is of the type skilled-cargo-111.appspot.com/comunapp/, while you probably only set up the handler for the / path, as you did with the default module.

If you're using Python, try updating your code to something like:

comunapp = webapp2.WSGIApplication([
    ('/comunapp/*', ComunApp),
], debug=True)

It should do the trick.

Also for the "api" path, you should add the "/api/" handler in the default module code.

You could check if dispatch file is working correctly by checking the logs for the comunapp module in the Developers' Console. If you see the requests for /comunapp/* URLs but get a 404 error is what I mentioned earlier. If you wouldn't see anything of those URLs appearing in the comunapp module logs, then the dispatch file is the key to solve the issue.



来源:https://stackoverflow.com/questions/25978198/appengine-module-routing-with-dispatch-yaml-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!