-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (35 loc) · 1.2 KB
/
main.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
package main
import (
"io/ioutil"
"net/http"
)
var fwClient = NewForwardingHTTPClient()
func handler(w http.ResponseWriter, r *http.Request) {
res, err := fwClient.NewForwardingRequest(r)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// accept ALL THE THINGS
w.Header().Set("Content-Type", r.Header.Get("content-type"))
w.Header().Set("Access-Control-Allow-Origin", r.Header.Get("origin"))
w.Header().Set("Access-Control-Allow-Credentials", "true")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
// might be a good idea to use * https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers
w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, X-HTTP-Method-Override")
w.Write(body)
return
}
func main() {
http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {})
http.HandleFunc("/", handler)
if err := http.ListenAndServe(":8080", nil); err != nil {
panic(err)
}
}