-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include proxy pass to frontend and cookie for API address
- Loading branch information
1 parent
5c92ab1
commit 705567f
Showing
86 changed files
with
17,152 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package middlewares | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
) | ||
|
||
const cookieKey = "gocity_api" | ||
|
||
type Middleware func(http.Handler) http.Handler | ||
|
||
func setAPICookie(w http.ResponseWriter, url string) { | ||
expire := time.Now().Add(24 * time.Hour) | ||
cookie := http.Cookie{ | ||
Name: cookieKey, | ||
Value: url, | ||
Path: "/", | ||
Expires: expire, | ||
MaxAge: 90000, | ||
} | ||
http.SetCookie(w, &cookie) | ||
} | ||
|
||
func APIHeader(APIUrl string) Middleware { | ||
return func(next http.Handler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
setAPICookie(w, APIUrl) | ||
next.ServeHTTP(w, r) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package handle | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httputil" | ||
"net/url" | ||
|
||
"github.com/prometheus/common/log" | ||
) | ||
|
||
const frontendURL = "https://go-city.github.io" | ||
|
||
func FrontEndProxy(w http.ResponseWriter, baseRequest *http.Request) { | ||
baseURL, err := url.Parse(frontendURL) | ||
if err != nil { | ||
log.Error(err) | ||
w.WriteHeader(http.StatusServiceUnavailable) | ||
} | ||
|
||
proxy := httputil.NewSingleHostReverseProxy(&url.URL{ | ||
Scheme: baseURL.Scheme, | ||
Host: baseURL.Host, | ||
}) | ||
|
||
req := baseRequest | ||
req.URL.Scheme = baseURL.Scheme | ||
req.URL.Host = baseURL.Host | ||
req.Host = baseURL.Host | ||
|
||
proxy.ServeHTTP(w, req) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.