Search code examples
google-app-engine

How to request my services on Google App Engine?


I've deployed a PHP application with 2 services on Google App Engine: admin and api.

I use a configuration file to route the requests.

My problem is that I can't route requests to my services. Only to the default.

Here is the structure:

|-- 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";

When I send a request: https://SERVICE_ID-dot-PROJECT_ID.REGION_ID.r.appspot.com or https://PROJECT_ID.REGION_ID.r.appspot.com the response is the expected one: Not found.

But when I send a request: https://SERVICE_ID-dot-PROJECT_ID.REGION_ID.r.appspot.com/API/api/ or https://PROJECT_ID.REGION_ID.r.appspot.com/API/api/ the response is an error code 500 instead of: Welcome to api service.

What is the problem ? Configuration ? Request urls ? Other ?


Solution

  • The problem was in the yaml files:

    new 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
    

    new admin/admin.yaml:

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

    new API/api.yaml:

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

    No more routing problem.