@nuxfly/core
Version:
Nuxt module for Fly.io integration with storage and database support
63 lines (62 loc) • 2.49 kB
TypeScript
export interface FlyProxyHeaders {
/** Client IP Address from Fly Proxy perspective */
clientIP?: string;
/** Original connection port that client connected to */
forwardedPort?: string;
/** Three letter region code where connection was accepted */
region?: string;
/** Comma separated list of IP addresses (client + proxies) */
forwardedFor?: string;
/** Original client protocol: 'http' or 'https' */
forwardedProto?: 'http' | 'https';
/** Original connection port set by client */
forwardedPortClient?: string;
/** SSL status: 'on' or 'off' */
forwardedSSL?: 'on' | 'off';
/** Proxy route path and protocols used */
via?: string;
}
export interface FlyProxyInfo {
/** All Fly Proxy headers */
headers: FlyProxyHeaders;
/** Client IP address (prioritizes Fly-Client-IP over X-Forwarded-For) */
clientIP: string | null;
/** Region where the request was processed */
region: string | null;
/** Whether the connection used SSL */
isSSL: boolean;
/** Original protocol used by client */
protocol: 'http' | 'https' | null;
/** Port the client connected to */
port: string | null;
/** Parse X-Forwarded-For header to get client and proxy IPs */
getForwardedIPs(): string[];
/** Check if request is from a specific region */
isFromRegion(regionCode: string): boolean;
/** Get the original client IP from X-Forwarded-For (first IP) */
getOriginalClientIP(): string | null;
}
/**
* Parse Fly Proxy headers from a headers object
* @param headers - Headers object (e.g., from request.headers)
*/
export declare function parseFlyProxyHeaders(headers: Record<string, string | string[] | undefined>): FlyProxyInfo;
/**
* Composable for accessing Fly Proxy headers and utilities
* Provides easy access to client IP, region, SSL status, and other proxy information
*
* Note: This composable works best when used in server-side contexts where headers are available.
* On the client-side, it will return empty values.
*/
export declare function useFlyProxy(): FlyProxyInfo;
/**
* Server-only composable for accessing Fly Proxy headers
* Throws an error if used on client-side
*/
export declare function useFlyProxyServer(): FlyProxyInfo;
/**
* Use Fly Proxy headers from a Nuxt event handler
* @param event - H3 event object from defineEventHandler
*/
export declare function useFlyProxyFromEvent(event: any): FlyProxyInfo;
export default useFlyProxy;