UNPKG

@aziontech/opennextjs-azion

Version:
31 lines (30 loc) 1.13 kB
/* eslint-disable @typescript-eslint/no-explicit-any */ /** * This code was originally copied and modified from the @opennextjs/cloudflare repository. * Significant changes have been made to adapt it for use with Azion. */ const azionContextSymbol = Symbol.for("__azion-context__"); export function getAzionContext(options = { async: false }) { return options.async ? getAzionContextAsync() : getAzionContextSync(); } function getAzionContextFromGlobalScope() { const global = globalThis; return global[azionContextSymbol]; } function getAzionContextSync() { const azionContext = getAzionContextFromGlobalScope(); if (azionContext) { return azionContext; } throw new Error(`\n\nERROR: \`getAzionContext\` has been called without having called`); } /** * Utility to get the current Azion context in async mode */ async function getAzionContextAsync() { const azionContext = getAzionContextFromGlobalScope(); if (azionContext) { return azionContext; } throw new Error(`\n\nERROR: \`getAzionContext\` has been called in async mode but the context is not available.\n`); }