在dispatch.yaml的同一个域中配置两个服务 [英] Configuring two services on the same domain in dispatch.yaml

查看:99
本文介绍了在dispatch.yaml的同一个域中配置两个服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

争取让这个工作。我有一个由两个服务组成的应用程序 - Angular中的前端,Node中的后端。



调度:

<$ p $ - url:< frontend-app> -dot-apt-aleph-767.appspot.com/
服务:< frontend-app>
- url:< frontend-app> -dot-apt-aleph-767.appspot.com/backend/
服务:< backend-app>

这是 gcloud app describe :

  dispatchRules:
- domain:< frontend-app> -dot-apt-aleph-767.appspot .com
路径:/
服务:< frontend-app>

- domain:< frontend-app> -dot-apt-aleph-767.appspot.com
path:/ backend / *
service:< frontend-app> ;

当我导航到前端应用程序的url时,它按预期工作。但是,当我访问< frontend-app> -dot-apt-aleph-767.appspot.com/backend 时,我得到了一个404。它没有任何意义,因为当我直接浏览后端URL时,它可以按预期工作。



plzhalp。

解决方案

为此,您需要您的后端服务处理对 /< somepath> 和<$ c $的请求c> / backend /< somepath> 以相同的方式。

检查您的后端应用程序日志,您会看到您期望它处理的请求,但是它对404的响应包含 / backend 前缀,而直接到后端URL的请求不会。



还要注意调度规则的顺序很重要 - 你首先需要更具体的一个,否则它将永远不会被达到,因为更通用的将在它之前匹配请求。您可能还想在请求路径中添加一些通配符:

  dispatch:
- url:<< ; frontend-app> -dot-apt-aleph-767.appspot.com/backend/*
service:< backend-app>
- url:< frontend-app> -dot-apt-aleph-767.appspot.com/*
service:< frontend-app>

进一步细化:

>

所以,只要这个就足够了:

 调度:
- url :* / backend / *
服务:< backend-app>

或者,您可以放弃< frontend-app> -dot- apt-aleph-767.appspot.com/backend /来自调度文件的URL并教你的前端服务接受,但是重定向任何 / backend /< somepath> 要求它看到< backend-app> -dot-apt-aleph-767.appspot.com/< somepath>


Battling to get this to work. I have an app composed of two services - frontend in Angular, backend in Node.

dispatch:

  - url: "<frontend-app>-dot-apt-aleph-767.appspot.com/"
    service: <frontend-app>
  - url: "<frontend-app>-dot-apt-aleph-767.appspot.com/backend/"
    service: <backend-app>

This is the output from gcloud app describe:

dispatchRules:
- domain: <frontend-app>-dot-apt-aleph-767.appspot.com
  path: /
  service: <frontend-app>

- domain: <frontend-app>-dot-apt-aleph-767.appspot.com
  path: /backend/*
  service: <frontend-app>

When I navigate to the url for the frontend app, it works as expected. However, I get a 404 when I go to <frontend-app>-dot-apt-aleph-767.appspot.com/backend. It doesn't make sense because when I navigate straight to the backend URL, it works as expected.

plzhalp.

解决方案

For this to work you need your backend service to handle requests to both /<somepath> and /backend/<somepath> in an identical manner.

Check your backend app log and you'll see that the request you were expecting it to handle but which it responded to with the 404 contains a /backend prefix, while the request going straight to the backend URL doesn't.

Also note that the order of the dispatch rules matters - you want the more specific one first, otherwise it'll never be reached since the more generic one will match the request before it. And you may want to put some wildcards as well on the request path:

dispatch:
- url: "<frontend-app>-dot-apt-aleph-767.appspot.com/backend/*"
  service: <backend-app>
- url: "<frontend-app>-dot-apt-aleph-767.appspot.com/*"
  service: <frontend-app>

Further refining this:

So just this should suffice:

dispatch:
- url: "*/backend/*"
  service: <backend-app>

Alternatively you can drop the "<frontend-app>-dot-apt-aleph-767.appspot.com/backend/" URL from the dispatch file and teach your frontend service to accept, but redirect any /backend/<somepath> requests it sees to <backend-app>-dot-apt-aleph-767.appspot.com/<somepath>.

这篇关于在dispatch.yaml的同一个域中配置两个服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆