@aziontech/opennextjs-azion
Version:
Azion builder for Next.js apps
66 lines (65 loc) • 2.35 kB
JavaScript
/**
* This code was originally copied and modified from the @opennextjs/cloudflare repository.
* Significant changes have been made to adapt it for use with Azion.
*/
import AzionWrapperEdge from "../core/overrides/wrapper/azion-wrapper-edge";
/**
* Defines the OpenNext configuration that targets the Azion adapter
*
* @param config options that enabled you to configure the application's behavior
* @returns the OpenNext configuration object
*/
export function defineAzionConfig(config = {}) {
const { incrementalCache, tagCache, queue, wrapper, routePreloadingBehavior } = config;
return {
default: {
override: {
wrapper: resolveWrapper(wrapper),
converter: "edge",
proxyExternalRequest: "fetch",
incrementalCache: resolveIncrementalCache(incrementalCache),
tagCache: resolveTagCache(tagCache),
queue: resolveQueue(queue),
},
routePreloadingBehavior,
},
// node:crypto is used to compute cache keys and node:stream is used to wrapper
edgeExternals: ["node:crypto", "node:stream"],
middleware: {
external: true,
override: {
// TODO: in the future move to the open-next aws package
wrapper: () => AzionWrapperEdge,
converter: "edge",
proxyExternalRequest: "fetch",
incrementalCache: resolveIncrementalCache(incrementalCache),
tagCache: resolveTagCache(tagCache),
queue: resolveQueue(queue),
},
},
};
}
function resolveIncrementalCache(value = "dummy") {
if (typeof value === "string") {
return value;
}
return typeof value === "function" ? value : () => value;
}
function resolveTagCache(value = "dummy") {
if (typeof value === "string") {
return value;
}
return typeof value === "function" ? value : () => value;
}
function resolveQueue(value = "dummy") {
if (typeof value === "string") {
return value;
}
return typeof value === "function" ? value : () => value;
}
function resolveWrapper(value = "dummy") {
if (typeof value === "string") {
return value;
}
return typeof value === "function" ? value : () => value;
}