dispatch.yaml

defalut

src/default/app.yaml

application: lucky-antler-166302
version: 1
runtime: go
api_version: go1.8

handlers:
- url: /.*
  script: _go_app
  secure: always

src/default/handler.go

package app

import (
    "fmt"
    "net/http"
)

func init() {
    http.HandleFunc("/", handler)
}

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hello, default!")
}

app1

src/app1/app1.yaml

application: lucky-antler-166302
module: app1
version: 1
runtime: go
api_version: go1.8

handlers:
- url: /.*
  script: _go_app
  secure: always

src/app1/handler.go

package app1

import (
    "fmt"
    "net/http"
)

func init() {
    http.HandleFunc("/app1", handler)
}

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hello, app1")
}

app2

src/app2/app2.yaml

application: lucky-antler-166302
module: app2
version: 1
runtime: go
api_version: go1.8

handlers:
- url: /.*
  script: _go_app
  secure: always

src/app2/handler.go

package app2

import (
    "fmt"
    "net/http"
)

func init() {
    http.HandleFunc("/app2", handler)
}

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hello, app2!")
}

dispatch.yaml

src/dispatch.yaml

dispatch:
  # Default service serves the typical web resources and all static resources.
  - url: "*/favicon.ico"
    service: default

  # Default service serves simple hostname request.
  # - url: "lucky-antler-166302.appspot.com/"
  #   service: default

  # Send all mobile traffic to the mobile frontend.
  - url: "*/app1/*"
    service: app1

  # Send all work to the one static backend.
  - url: "*/app2/*"
    service: app2

デプロイ

  1. goapp deploy で各アプリをデプロイ
  2. 以下のコマンドでdispatch.yamlをデプロイ
    gcloud app deploy dispatch.yaml –project lucky-antler-166302

確認

  • https://lucky-antler-166302.appspot.com/
    Hello, default!

  • https://lucky-antler-166302.appspot.com/app1/
    Hello, app1

  • https://lucky-antler-166302.appspot.com/app2/
    Hello, app2

注意事項

/app1/ にアクセスした場合に、app1 moduleの /app1 にルーティングされる