@stacksjs/rpx
Version:
A modern and smart reverse proxy.
41 lines (40 loc) • 1.77 kB
TypeScript
/**
* Normalize a `redirect` config (string shorthand or object) into a
* {@link ResolvedRedirect}. A `to` without a scheme is treated as `https://<to>`
* (a public redirect should land on TLS), and any trailing slash is trimmed so
* appending the request path joins cleanly.
*/
export declare function resolveRedirect(input: string | RedirectRouteConfig): ResolvedRedirect;
/**
* Build the `Location` value for a redirect route. With `preservePath` the
* request `pathname` + `search` (e.g. `/a/b?x=1`) is appended to the target
* base; otherwise the bare target is used. `pathname` always starts with `/`
* and `search` carries its own leading `?` (or is empty).
*/
export declare function buildRedirectLocation(redirect: ResolvedRedirect, pathname: string, search: string): string;
/**
* Redirect routes: a gateway host whose requests are answered with an HTTP
* redirect (a `Location` response) instead of being proxied to an upstream or
* served from disk. The canonical use is pointing an alternate/parked domain at
* its primary host — e.g. `very-good-adblock.org` → `https://verygoodadblock.org`
* — while preserving deep links: the request path + query are appended to the
* target by default.
*
* Kept transport-agnostic and dependency-free so both the shared `:443` handler
* and tests can use it directly.
*/
/**
* Public redirect config for a route. A bare string is shorthand for a
* permanent (301) redirect to that URL, path-preserving.
*/
export declare interface RedirectRouteConfig {
to: string
status?: 301 | 302 | 307 | 308
preservePath?: boolean
}
/** A normalized redirect, ready to serve. */
export declare interface ResolvedRedirect {
to: string
status: 301 | 302 | 307 | 308
preservePath: boolean
}