首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Google App Engine上请求我的服务?

如何在Google App Engine上请求我的服务?
EN

Stack Overflow用户
提问于 2021-11-03 13:51:00
回答 1查看 39关注 0票数 0

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

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

我的问题是我不能将请求路由到我的服务。仅设置为默认值。

结构是这样的:

代码语言:javascript
复制
|-- admin
    |-- public
        |-- index.php
    |-- admin.yaml
|-- API
    |-- api
        |-- index.php
    |-- api.yaml
|-- dispatch.yaml
|-- index.php

dispatch.yaml:

代码语言:javascript
复制
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:

代码语言:javascript
复制
runtime: php73
service: admin

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

Api.yaml接口:

代码语言:javascript
复制
runtime: php73
service: api

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

index.php:echo "Not found";

管理/公共/索引.php:echo "Welcome to admin service";

api接口:echo "Welcome to api service";

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

但是当我发送一个请求: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

问题出在哪里?配置?请求urls?其他的?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-11 13:22:02

问题出在yaml文件中:

新的dispatch.yaml

代码语言:javascript
复制
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/admin.yaml:

代码语言:javascript
复制
runtime: php73
service: admin

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

新接口/api.yaml:

代码语言:javascript
复制
runtime: php73
service: api

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

不再有路由问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69826066

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档