【问题标题】:How to request my services on Google App Engine?如何在 Google App Engine 上请求我的服务?
【发布时间】:2021-11-03 13:50:59
【问题描述】:

我在 Google App Engine 上部署了一个包含 2 个服务的 PHP 应用程序:admin 和 api。

我使用配置文件来路由请求。

我的问题是我无法将请求路由到我的服务。只使用默认值。

结构如下:

|-- admin
    |-- public
        |-- index.php
    |-- admin.yaml
|-- API
    |-- api
        |-- index.php
    |-- api.yaml
|-- dispatch.yaml
|-- index.php

dispatch.yaml:

dispatch: 
  # Send all api traffic to the API.
  - url: "*/API/api/*"
    service: api

  # Send all admin traffic to the admin.
  - url: "*/admin/public/*"
    service: admin
    
  # Default service serves simple hostname request.
  - url: "*/*"
    service: default

admin/admin.yaml:

runtime: php73
service: admin

handlers:
- url: /admin/public/.*
  script: /admin/public/index.php

API/api.yaml:

runtime: php73
service: api

handlers:
- url: /API/api/.*
  script: /API/api/index.php

index.php:echo "Not found";

admin/public/index.php:echo "Welcome to admin service";

API/api/index.php:echo "Welcome to api service";

当我发送请求:https://SERVICE_ID-dot-PROJECT_ID.REGION_ID.r.appspot.comhttps://PROJECT_ID.REGION_ID.r.appspot.com 时,响应是预期的:未找到。

但是当我发送请求时:https://SERVICE_ID-dot-PROJECT_ID.REGION_ID.r.appspot.com/API/api/https://PROJECT_ID.REGION_ID.r.appspot.com/API/api/ 响应是 error code 500 而不是:Welcome to api service

有什么问题?配置 ?请求网址?其他?

【问题讨论】:

  • 您还可以从您的应用中添加logs 吗?

标签: google-app-engine


【解决方案1】:

问题出在 yaml 文件中:

新的 dispatch.yaml

dispatch: 
  # Send all api traffic to the API.
  - url: "SERVICE_ID-dot-PROJECT_ID.REGION_ID.r.appspot.com"
    service: api

  # Send all admin traffic to the admin.
  - url: "SERVICE_ID-dot-PROJECT_ID.REGION_ID.r.appspot.com"
    service: admin
    
  # Default service serves simple hostname request.
  - url: "PROJECT_ID.REGION_ID.r.appspot.com"
    service: default

新管理员/admin.yaml:

runtime: php73
service: admin

handlers:
- url: /.*
  script: /admin/public/index.php

新 API/api.yaml:

runtime: php73
service: api

handlers:
- url: /.*
  script: /API/api/index.php

不再有路由问题。

【讨论】:

    猜你喜欢
    • 2015-03-07
    • 2013-05-22
    • 2010-09-14
    • 1970-01-01
    • 2018-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多