From 6f4e1e1795fe3c1d7857a39cd5d7ed18dee49796 Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Wed, 5 Dec 2018 16:39:28 -0500 Subject: [PATCH] Add GAE app frontend to serve custom domain traffic --- fwd/.gcloudignore | 25 +++++++++++++++++++++++++ fwd/app.go | 32 ++++++++++++++++++++++++++++++++ fwd/app.yaml | 2 ++ 3 files changed, 59 insertions(+) create mode 100644 fwd/.gcloudignore create mode 100644 fwd/app.go create mode 100644 fwd/app.yaml diff --git a/fwd/.gcloudignore b/fwd/.gcloudignore new file mode 100644 index 0000000..199e6d9 --- /dev/null +++ b/fwd/.gcloudignore @@ -0,0 +1,25 @@ +# This file specifies files that are *not* uploaded to Google Cloud Platform +# using gcloud. It follows the same syntax as .gitignore, with the addition of +# "#!include" directives (which insert the entries of the given .gitignore-style +# file at that point). +# +# For more information, run: +# $ gcloud topic gcloudignore +# +.gcloudignore +# If you would like to upload your .git directory, .gitignore file or files +# from your .gitignore file, remove the corresponding line +# below: +.git +.gitignore + +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib +# Test binary, build with `go test -c` +*.test +# Output of the go coverage tool, specifically when used with LiteIDE +*.out \ No newline at end of file diff --git a/fwd/app.go b/fwd/app.go new file mode 100644 index 0000000..4c2cb0e --- /dev/null +++ b/fwd/app.go @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "io" + "log" + "net/http" +) + +const appJunk = "https://app-j33hbo5ywa-uc.a.run.app" + +func main() { + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + req, err := http.NewRequest(r.Method, fmt.Sprintf("%s/%s", appJunk, r.URL.Path), nil) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + resp, err := http.DefaultClient.Do(req) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + for k, v := range resp.Header { + w.Header().Set(k, v[0]) + } + w.WriteHeader(resp.StatusCode) + io.Copy(w, resp.Body) + }) + log.Fatal(http.ListenAndServe(":8080", nil)) +} diff --git a/fwd/app.yaml b/fwd/app.yaml new file mode 100644 index 0000000..1b7aec3 --- /dev/null +++ b/fwd/app.yaml @@ -0,0 +1,2 @@ +runtime: go111 +