blob: 19b9afd571df7a54dfdfbdce740ea34da6934ef8 (
plain) (
blame)
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
|
// SPDX-License-Identifier: BSD-2-Clause
// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
)
var reverseProxy *httputil.ReverseProxy
// This init sets up the reverse proxy. Go's NewSingleHostReverseProxy is
// sufficient for our use case.
func init() {
parsedURL, err := url.Parse(destHost)
if err != nil {
log.Fatal(err)
}
reverseProxy = httputil.NewSingleHostReverseProxy(parsedURL)
}
// proxyRequest proxies the incoming request to the destination host.
func proxyRequest(writer http.ResponseWriter, request *http.Request) {
reverseProxy.ServeHTTP(writer, request)
}
|