-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevproxy.go
More file actions
55 lines (48 loc) · 1.37 KB
/
devproxy.go
File metadata and controls
55 lines (48 loc) · 1.37 KB
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
46
47
48
49
50
51
52
53
54
55
//go:build ignore
// devproxy.go is a local-only dev server for testing the site against the live
// Sumo MCP API without CORS. It serves the static site and reverse-proxies /mcp
// to https://api.sumo-mcp.com, stripping browser Origin/Sec-Fetch headers so the
// upstream treats the call as same-origin/non-browser.
//
// Usage:
//
// go run devproxy.go # then open http://localhost:8000
//
// This file is not part of the deployed site (build tag "ignore").
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
)
func main() {
const addr = ":8000"
target, err := url.Parse("https://api.sumo-mcp.com")
if err != nil {
log.Fatal(err)
}
proxy := &httputil.ReverseProxy{
Rewrite: func(r *httputil.ProxyRequest) {
r.SetURL(target)
r.Out.Host = target.Host
// Make the upstream see a plain server-to-server request so its
// cross-origin protection allows it.
r.Out.Header.Del("Origin")
r.Out.Header.Del("Sec-Fetch-Site")
r.Out.Header.Del("Sec-Fetch-Mode")
r.Out.Header.Del("Sec-Fetch-Dest")
},
}
mux := http.NewServeMux()
mux.Handle("/mcp", proxy)
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
http.ServeFile(w, r, "index.html")
})
log.Printf("serving site + /mcp proxy on http://localhost%s", addr)
log.Fatal(http.ListenAndServe(addr, mux))
}