Azion `Utils` package

The Azion Utils package provides a set of utility functions designed to simplify common tasks when working with Azion Edge Functions. These utilities cover tasks such as routing for Single Page Applications (SPA) and Multi-Page Applications (MPA), as well as parsing and debugging incoming requests.

Go to Azion Libraries Overview

Usage

mountSPA

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). It determines whether the incoming request is for a static asset or an application route and then mounts the appropriate request URL for fetching the required resource.

Example:

import { mountSPA } from 'azion/utils';
const myApp: Response = await mountSPA('https://example.com/');
console.log(myApp);
// Fetches: file:///index.html
// Response object representing the content of index.html

mountMPA

The mountMPA function handles requests for Multi-Page Applications (MPA) at the edge. It processes the incoming request URL, constructs the appropriate asset path, and fetches the corresponding response from the origin server or edge cache.

TypeScript example:

import { mountMPA } from 'azion/utils';
const myApp: Response = await mountMPA('https://example.com/about');
console.log(myApp);
// Fetches: file:///about/index.html
// Response object representing the content of about/index.html

parseRequest

The parseRequest function is designed to parse and log the details of an incoming request. It 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.

TypeScript example:

import { parseRequest } from 'azion/utils';
import type { ParsedRequest } from 'azion/utils';
const parsedRequest: ParsedRequest = await parseRequest(event);
console.log(parsedRequest);

Contributors