【问题标题】:How to handle Polymer routing in Google Appengine如何在 Google Appengine 中处理 Polymer 路由
【发布时间】:2015-01-30 07:03:38
【问题描述】:

我正在尝试在 Google App Engine 上运行这个 Polymer 应用程序 (https://divshot.com/blog/web-components/building-a-qa-system-with-polymer-and-firebase/)。通过设置路由,我能够让第一页工作

webapp2.Route(r'/polymer', handler=project_handler.PolymerHandler, name='polymer'),

但是当 Github oAuth 成功将登录用户返回到回调 URL 时,问题输入屏幕 (list.html) 不显示。 (仅供参考。当我在 GAE 之外运行完全相同的项目时,它工作得很好。所以我相信问题出在我的 GAE 路由设置上。)

<core-header-panel>
  <div class="core-header">
    <core-toolbar>
      <div flex>Firebase Q&amp;A</div>
      <paper-menu-button halign="right">
        <paper-icon-button icon="social:person"></paper-icon-button>
        <paper-dropdown class="dropdown" transition="">
          <core-menu class="menu">
            <paper-item on-click="{{login}}" hidden?="{{!statusKnown || user}}">Login</paper-item>
            <paper-item on-click="{{logout}}" hidden?="{{!statusKnown || !user}}">Logout</paper-item>
          </core-menu>
        </paper-dropdown>
      </paper-menu-button>
      <template if="{{user}}">{{user.github.username}}</template>
    </core-toolbar>
  </div>
  <div class="content">
    <app-router>  <!-- This handles routing for Polymer app -->
      <app-route path="/" import="/app/component/questions/list.html" element="qa-list"></app-route>
      <app-route path="/app/component/questions/:id" import="/app/component/questions/view.html" element="qa-view"></app-route>
    </app-router>
  </div>
</core-header-panel>

显然这个应用路由器不工作。

你能指出我正确的方向吗?谢谢。

项目结构

项目根目录
\应用程序\
\app\index.html
\app\组件
\app\component\qa.html
\app\component\questions\list.html
\bower_components
\app.yaml

App.yaml

handlers:

- url: /components
  static_dir: bower_components

- url: /app
  static_dir: app

- url: /
  static_files: app/index\.html
  upload: app/index\.html

【问题讨论】:

    标签: google-app-engine polymer


    【解决方案1】:

    由于您尝试运行的项目似乎完全由静态文件组成,因此无需在 webapp2 中定义路由或使用任何 python 代码,因为 GAE 可以通过一些 app.yaml 设置来提供所有这些,假设如果您在项目的根目录中同时拥有 bower_componentsapp 文件夹,则类似于:

    handlers:
    - url: /bower_components
      static_dir: bower_components
    
    - url: /app
      static_dir: app
    
    - url: /
      static_files: app/index\.html
      upload: app/index\.html
    

    【讨论】:

    • 感谢您的回复。我按照你的建议尝试了,但不幸的是我无法让它工作。根据开发者工具中的网络日志,应用甚至不会尝试获取这个 list.html 文件。
    • 您能继续与您部署的任何内容共享 *.appspot.com 链接吗?另外,也可以在这里添加app.yaml的内容。
    • @MihailRussu,完全同意我们需要查看app.yaml(如果是多模块应用程序,则需要查看dispatch.yaml,但情况似乎并非如此)——第一级路由,毕竟!
    • 看来你需要为 /app/index.html 创建一个路由。在本地它可能是 / 但在服务器上看起来你的家是 /app/index.html。
    • 在将 index.html 移动到项目根目录并将 app.yaml 更改为 - url: / static_file: index.html upload: index.html 我很惊讶 app-路由器现在似乎也可以工作。当 app.yaml 和 app-router 将 url:/ 指向两个不同的文件(即分别为 \index.html 和 app\component\questions\list.html)时,我仍然不确定这是如何工作的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-23
    • 1970-01-01
    • 1970-01-01
    • 2019-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多