@scayle/storefront-nuxt
Version:
Nuxt integration for the SCAYLE Commerce Engine and Storefront API
19 lines (18 loc) • 638 B
JavaScript
import { defineNitroPlugin } from "nitropack/runtime/plugin";
import { fetchWithEvent } from "h3";
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook("request", (event) => {
const $fetch = globalThis.$fetch;
const envContext = (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
event.node.req?.__unenv__
);
if (envContext) {
Object.assign(event.context, envContext);
}
event.context.$fetchWithContext = ((req, init) => fetchWithEvent(event, req, init, {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fetch: $fetch
}));
});
});