【发布时间】:2018-08-02 21:09:09
【问题描述】:
我有一个在应用引擎标准上运行的 Java Web 应用程序。
它曾经在我的项目中作为默认服务运行,我有这个 cron 作业来清除旧会话: https://groups.google.com/forum/#!msg/google-appengine-java/Tw2a8cYz05o/UgsWaoQhWYcJ
我按照此文档将我的单体 Web 应用程序拆分为微服务: https://cloud.google.com/appengine/docs/standard/java/microservices-on-app-engine
前端和后端都在 Java Web 应用程序中,但现在我正在 React.js 中开发一个前端,并将该前端作为同一应用程序引擎项目中的默认服务运行(使用 nodejs 运行时)。
java web 应用现在只作为后端,所以我将服务设置为:<service>backend</service>
我使用 dispatch.yaml 文件将 /static/ 路径指向前端,将所有其他路径指向后端。
# Rules for dispatch file...
# Put specific cases at the top, other
dispatch:
# Apart from the react frontend on a custom url.
- url: "blindepoule.appspot.com/static/*"
service: default
# Route the rest to the backend
- url: "blindepoule.appspot.com/*"
service: backend
这很好用!但是 sessioncleanup cron 作业现在失败了:
它确实直接在特定的服务 url 上工作: https://backend-dot-blindepoule.appspot.com/_ah/sessioncleanup?clear
但不在: https://blindepoule.appspot.com/_ah/sessioncleanup?clear
查看前端服务的日志服务器时,似乎前端收到/_ah/sessioncleanup调用并返回404。我的dispatch.yaml没有将调用重定向到后端服务。
我想添加对 dispatch.yaml 的显式引用,但文档说它将忽略并且 url 以“_ah”开头。我还读到您可以在 appengine-web.xml 文件中指定一个目标,但您必须在其中输入一个版本。然后我每次更新版本时都必须更新它(我做了很多,因为它在应用程序引擎中很容易)。在我的情况下,我更愿意指定 cron 作业需要查看后端服务: https://backend-dot-blindepoule.appspot.com/
更新:我尝试将 servlet 更改为没有 _ah 的路径,将“_ah”更改为“api”。
<servlet>
<servlet-name>_ah_sessioncleanup</servlet-name>
<servlet-class>com.google.apphosting.utils.servlet.SessionCleanupServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>_ah_sessioncleanup</servlet-name>
<url-pattern>/api/sessioncleanup</url-pattern>
</servlet-mapping>
<security-constraint>
<web-resource-collection>
<web-resource-name>Sessions Removal</web-resource-name>
<url-pattern>/api/sessioncleanup</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
这在开发服务器上本地运行时有效,但在应用引擎上我得到了 404(日志显示它在后端服务上得到了 404,所以它没有被错误地映射): https://blindpool.com/api/sessioncleanup?clear 即使在服务的直接网址上(以前有效): https://backend-dot-blindepoule.appspot.com/api/sessioncleanup?clear 如果 com.google.apphosting.utils.servlet.SessionCleanupServlet 不是来自 _ah 模式,则可能有一个先决条件抛出 404。
我想我可以编写自己的 servlet 来删除记录。
有什么想法吗?我的完整来源:https://github.com/Leejjon/Blindpool
【问题讨论】: