webproxy

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package webproxy reverse-proxies a browser to an upstream web app and rewrites the response so the app works under a gateway sub-path. It is protocol-neutral: a plugin resolves how to reach the upstream (a Kubernetes Service/Pod via the API server proxy, a Docker container's port, …) and hands the request here for the proxying + HTML/redirect/cookie rewriting and the in-scope service worker.

Index

Constants

View Source
const SWFile = "__shellcn_sw.js"

SWFile is the in-scope service worker that re-routes the app's root-absolute requests (bundler chunks, dynamic imports, CSS) under the proxy prefix.

Variables

This section is empty.

Functions

func IsTLSPort

func IsTLSPort(port int) bool

IsTLSPort is a best-effort guess that a port serves TLS, by the conventional "443" suffix (443, 8443, 9443, …). Used only when no protocol metadata exists.

func Serve

func Serve(w http.ResponseWriter, r *http.Request, o Options)

Serve reverse-proxies r to the upstream and rewrites the response so the app's absolute paths, redirects, fetches, and assets resolve back under PublicPrefix.

func ServeWorker

func ServeWorker(w http.ResponseWriter, prefix string)

ServeWorker returns the service worker. Served from under the prefix, its default scope is the proxy path, so it controls the app's page and rewrites any root-absolute request it makes back under the prefix.

func WebSchemeFromName

func WebSchemeFromName(name string) (scheme string, ok bool)

WebSchemeFromName reads "http"/"https" from a port's conventional name (a Kubernetes/Swarm port name), reporting ok=false when it names no web protocol.

Types

type Options

type Options struct {
	// Base is the upstream's scheme://host; Transport dials it.
	Base      *url.URL
	Transport http.RoundTripper
	// UpstreamPath/UpstreamRawPath is the path to request on the upstream.
	UpstreamPath    string
	UpstreamRawPath string
	// PublicPrefix is the gateway path the app is served under (for rewriting).
	PublicPrefix string
	// SourcePrefix is a prefix the upstream itself injects into the app's links
	// (e.g. the Kubernetes API server proxy path) and that must be mapped back to
	// PublicPrefix. Empty when proxying straight to the app (Docker), where the
	// app emits its own root-relative paths.
	SourcePrefix string
}

Options describes one proxied request.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL