-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.go
45 lines (35 loc) · 944 Bytes
/
function.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package p
import (
"net/http"
"net/http/httputil"
"net/url"
"os"
"strconv"
)
var shouldEnableHttps = getBooleanConfig("enableHttps")
var shouldVerifyApiKey = getBooleanConfig("verifyApiKey")
func init() {
}
func Proxy(responseWriter http.ResponseWriter, request *http.Request) {
target, _ := url.Parse("https://api.predic8.de:443/shop/categories/")
proxy := httputil.NewSingleHostReverseProxy(target)
if shouldEnableHttps {
enableHttps(request, target)
}
if shouldVerifyApiKey {
}
proxy.ServeHTTP(responseWriter, request)
}
func getBooleanConfig(configParameterName string) bool {
result, _ := strconv.ParseBool(os.Getenv(configParameterName))
return result
}
func enableHttps(request *http.Request, target *url.URL) {
request.URL.Host = target.Host
request.URL.Scheme = target.Scheme
request.Header.Set("X-Forwarded-Host", request.Header.Get("Host"))
request.Host = target.Host
}
func Main() {
Proxy(nil, nil)
}