azion
Version:
Azion Packages for Edge Computing.
102 lines (97 loc) • 3.95 kB
TypeScript
import { m as mountMPAFunction, M as MountSPAFunction, P as ParseRequestFunction } from '../types-B4D9isr_.js';
/**
* @function
* @description The `mountMPA` function handles requests for Static Site Generation (SSG)
* at the edge, directly within a serverless worker.
* It processes the incoming request URL, constructs the appropriate asset path,
* and fetches the corresponding response from the SSG.
* @param {RequestURL} requestURL - The original URL from the event request.
* @returns {Promise<Response>} A promise that resolves to the response from the SSG.
* @example
* // Handle a request for a homepage
* // Input: mountMPA('https://example.com/');
* // Output: fetch('file:///index.html');
* @example
* // Handle a request for an asset (CSS file)
* // Input: mountMPA('https://example.com/styles/main.css');
* // Output: fetch('file:///styles/main.css');
* @example
* // Handle a request for a specific route
* // Input: mountMPA('https://example.com/about');
* // Output: fetch('file:///about/index.html');
*/
declare const mountMPA: mountMPAFunction;
/**
* @function
* @description The `mountSPA` function is designed to process requests to a Single Page Application (SPA)
* that's being computed at the edge of a Content Delivery Network (CDN).
*
* This function determines if the incoming request is for a static
* asset or a route within the application,
* and mounts the appropriate request URL for fetching the required resource from the origin server.
* @param {RequestURL} requestURL - The original URL from the incoming request.
* @returns {Promise<Response>} A promise that resolves to the response from the fetched resource.
* @example
* // Handle a request for a homepage
* // Input: mountSPA('https://example.com/');
* // Output: fetch('file:///index.html');
* @example
* // Handle a request for an asset (CSS file)
* // Input: mountSPA('https://example.com/styles/main.css');
* // Output: fetch('file:///styles/main.css');
* @example
* // Handle a request for a specific route
* // Input: mountSPA('https://example.com/about');
* // Output: fetch('file:///index.html');
*/
declare const mountSPA: MountSPAFunction;
/**
* @function
* @description The `parseRequest` function is designed to parse and log the details of an incoming request.
* This function extracts key information such as headers, cookies, body, and client data from the incoming FetchEvent,
* providing a structured object with all these details for further processing or logging purposes.
* @param {FetchEvent} event - The incoming FetchEvent object representing the request.
* @returns {Promise<object>} A promise that resolves to an object containing detailed information about the request.
* @example
* // Parse a GET request
* // Input: parseRequest(event);
* // Output: {
* // timestamp: "2024-08-14T12:34:56.789Z",
* // metadata: {
* // geoip_asn: "12345",
* // geoip_city: "Sao Paulo",
* // geoip_city_continent_code: "SA",
* // geoip_city_country_code: "BR",
* // geoip_city_country_name: "Brazil",
* // // ... other metadata fields
* // },
* // method: "GET",
* // url: {
* // full: "https://example.com/",
* // protocol: "https:",
* // hostname: "example.com",
* // path: "/",
* // query: {}
* // },
* // headers: { ... },
* // cookies: { ... },
* // body: null,
* // client: {
* // ip: "123.45.67.89",
* // userAgent: "Mozilla/5.0 ..."
* // },
* // referer: "Unknown",
* // origin: "Unknown",
* // cacheControl: "Unknown",
* // pragma: "Unknown",
* // contentType: "Unknown",
* // contentLength: "Unknown",
* // acceptLanguage: "Unknown",
* // acceptEncoding: "Unknown",
* // priority: "Unknown",
* // host: "Unknown",
* // authorization: "Not Present"
* // }
*/
declare const parseRequest: ParseRequestFunction;
export { mountMPA, mountSPA, parseRequest };