added download 2
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
import { d as defineEventHandler, s as setResponseStatus } from '../nitro/nitro.mjs';
|
||||
import 'node:http';
|
||||
import 'node:https';
|
||||
import 'node:events';
|
||||
import 'node:buffer';
|
||||
import 'node:fs';
|
||||
import 'node:path';
|
||||
import 'node:crypto';
|
||||
import 'vue';
|
||||
import 'node:url';
|
||||
import 'consola';
|
||||
import 'fast-xml-parser';
|
||||
import 'ipx';
|
||||
|
||||
const _nuxt = defineEventHandler((event) => {
|
||||
const pathname = event.node.req.url || "";
|
||||
if (pathname === "/_nuxt" || pathname === "/_nuxt/") {
|
||||
setResponseStatus(event, 204);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
export { _nuxt as default };
|
||||
@@ -1,78 +0,0 @@
|
||||
import { k as defineSitemapEventHandler } from '../../../nitro/nitro.mjs';
|
||||
import { createClient } from '@supabase/supabase-js';
|
||||
import 'node:http';
|
||||
import 'node:https';
|
||||
import 'node:events';
|
||||
import 'node:buffer';
|
||||
import 'node:fs';
|
||||
import 'node:path';
|
||||
import 'node:crypto';
|
||||
import 'vue';
|
||||
import 'node:url';
|
||||
import 'consola';
|
||||
import 'fast-xml-parser';
|
||||
import 'ipx';
|
||||
|
||||
let _client = null;
|
||||
function ensureClient() {
|
||||
if (_client) return _client;
|
||||
const SUPABASE_URL = useState("supabase-url").value;
|
||||
const SUPABASE_KEY = useState("supabase-key").value;
|
||||
if (!SUPABASE_URL || !SUPABASE_KEY) {
|
||||
console.warn("[supabase] Missing SUPABASE_URL/KEY");
|
||||
}
|
||||
_client = createClient(SUPABASE_URL, SUPABASE_KEY);
|
||||
return _client;
|
||||
}
|
||||
const supabase = new Proxy({}, {
|
||||
get(_t, prop, receiver) {
|
||||
const c = ensureClient();
|
||||
return Reflect.get(c, prop, receiver);
|
||||
},
|
||||
apply(_t, thisArg, argArray) {
|
||||
var _a, _b;
|
||||
return (_b = (_a = ensureClient()) == null ? void 0 : _a.apply) == null ? void 0 : _b.call(_a, thisArg, argArray);
|
||||
}
|
||||
});
|
||||
|
||||
const urls = defineSitemapEventHandler(async () => {
|
||||
const urls = [];
|
||||
try {
|
||||
const { data: categorys, error } = await supabase.from("collections").select(`title`);
|
||||
if (categorys && categorys.length) {
|
||||
categorys.forEach((item) => {
|
||||
urls.push(`/search/main?category=${item.title}`);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
try {
|
||||
const { data: brands, error } = await supabase.from("brands").select(`title`);
|
||||
if (brands && brands.length) {
|
||||
brands.forEach((item) => {
|
||||
urls.push(`/search/main?brand=${item.title}`);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
try {
|
||||
const { data: products, error } = await supabase.from("products").select(`title`);
|
||||
if (products && products.length) {
|
||||
products.forEach((item) => {
|
||||
urls.push(`/product_detail/${item.title}`);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
urls.push(`/`);
|
||||
urls.push(`/home`);
|
||||
urls.push(`/search`);
|
||||
urls.push(`/search/main`);
|
||||
urls.push(`/user`);
|
||||
return urls;
|
||||
});
|
||||
|
||||
export { urls as default };
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import { d as defineEventHandler, g as getRequestHeader, a as getCachedConfig, b as sendRedirect } from '../nitro/nitro.mjs';
|
||||
import 'node:http';
|
||||
import 'node:https';
|
||||
import 'node:events';
|
||||
import 'node:buffer';
|
||||
import 'node:fs';
|
||||
import 'node:path';
|
||||
import 'node:crypto';
|
||||
import 'vue';
|
||||
import 'node:url';
|
||||
import 'consola';
|
||||
import 'fast-xml-parser';
|
||||
import 'ipx';
|
||||
|
||||
const handler = defineEventHandler(async (event) => {
|
||||
const host = getRequestHeader(event, "host");
|
||||
const config = await getCachedConfig(host || "");
|
||||
if (config == null ? void 0 : config.storageLogo) {
|
||||
const remoteUrl = `${config.storageLogo}/favicon.ico`;
|
||||
return sendRedirect(event, remoteUrl, 302);
|
||||
}
|
||||
return sendRedirect(event, "https://node.newinsta.ir/", 302);
|
||||
});
|
||||
|
||||
export { handler as default };
|
||||
@@ -1,52 +0,0 @@
|
||||
import { d as defineEventHandler, c as getRequestHost, a as getCachedConfig, e as setResponseHeader } from '../nitro/nitro.mjs';
|
||||
import 'node:http';
|
||||
import 'node:https';
|
||||
import 'node:events';
|
||||
import 'node:buffer';
|
||||
import 'node:fs';
|
||||
import 'node:path';
|
||||
import 'node:crypto';
|
||||
import 'vue';
|
||||
import 'node:url';
|
||||
import 'consola';
|
||||
import 'fast-xml-parser';
|
||||
import 'ipx';
|
||||
|
||||
const manifest_webmanifest_get = defineEventHandler(async (event) => {
|
||||
const host = getRequestHost(event);
|
||||
const config = await getCachedConfig(host);
|
||||
const name = (config == null ? void 0 : config.appNameEn) || "App Name";
|
||||
const shortName = (config == null ? void 0 : config.appNameEn) || "App";
|
||||
const description = (config == null ? void 0 : config.description) || "Best Shopping App";
|
||||
const iconSrc = (config == null ? void 0 : config.storageLogo) ? `${config.storageLogo}/pwa-icon-192.png` : "/pwa-icon-192.png";
|
||||
const manifest = {
|
||||
name,
|
||||
short_name: shortName,
|
||||
description,
|
||||
id: "/",
|
||||
start_url: "/",
|
||||
display: "standalone",
|
||||
orientation: "portrait-primary",
|
||||
background_color: "#ffffff",
|
||||
theme_color: "#ffffff",
|
||||
icons: [
|
||||
{
|
||||
src: iconSrc,
|
||||
sizes: "192x192",
|
||||
type: "image/png",
|
||||
purpose: "any maskable"
|
||||
},
|
||||
{
|
||||
// اینجا فرض میکنیم فایل 512 هم کنار 192 هست
|
||||
src: iconSrc.replace("192", "512"),
|
||||
sizes: "512x512",
|
||||
type: "image/png",
|
||||
purpose: "any maskable"
|
||||
}
|
||||
]
|
||||
};
|
||||
setResponseHeader(event, "Content-Type", "application/manifest+json");
|
||||
return manifest;
|
||||
});
|
||||
|
||||
export { manifest_webmanifest_get as default };
|
||||
@@ -1,24 +0,0 @@
|
||||
import { d as defineEventHandler, g as getRequestHeader, a as getCachedConfig, b as sendRedirect } from '../nitro/nitro.mjs';
|
||||
import 'node:http';
|
||||
import 'node:https';
|
||||
import 'node:events';
|
||||
import 'node:buffer';
|
||||
import 'node:fs';
|
||||
import 'node:path';
|
||||
import 'node:crypto';
|
||||
import 'vue';
|
||||
import 'node:url';
|
||||
import 'consola';
|
||||
import 'fast-xml-parser';
|
||||
import 'ipx';
|
||||
|
||||
const handler = defineEventHandler(async (event) => {
|
||||
const host = getRequestHeader(event, "host");
|
||||
const config = await getCachedConfig(host || "");
|
||||
if (config == null ? void 0 : config.storageLogo) {
|
||||
return sendRedirect(event, `${config.storageLogo}/pwa-icon-192.png`, 302);
|
||||
}
|
||||
return sendRedirect(event, "https://node.newinsta.ir/default/pwa-icon-192.png");
|
||||
});
|
||||
|
||||
export { handler as default };
|
||||
@@ -1,24 +0,0 @@
|
||||
import { d as defineEventHandler, g as getRequestHeader, a as getCachedConfig, b as sendRedirect } from '../nitro/nitro.mjs';
|
||||
import 'node:http';
|
||||
import 'node:https';
|
||||
import 'node:events';
|
||||
import 'node:buffer';
|
||||
import 'node:fs';
|
||||
import 'node:path';
|
||||
import 'node:crypto';
|
||||
import 'vue';
|
||||
import 'node:url';
|
||||
import 'consola';
|
||||
import 'fast-xml-parser';
|
||||
import 'ipx';
|
||||
|
||||
const handler = defineEventHandler(async (event) => {
|
||||
const host = getRequestHeader(event, "host");
|
||||
const config = await getCachedConfig(host || "");
|
||||
if (config == null ? void 0 : config.storageLogo) {
|
||||
return sendRedirect(event, `${config.storageLogo}/pwa-icon-512.png`, 302);
|
||||
}
|
||||
return sendRedirect(event, "https://node.newinsta.ir/default/pwa-icon-192.png");
|
||||
});
|
||||
|
||||
export { handler as default };
|
||||
@@ -1,423 +0,0 @@
|
||||
import { createRenderer, getRequestDependencies, getPreloadLinks, getPrefetchLinks } from 'vue-bundle-renderer/runtime';
|
||||
import { l as buildAssetsURL, u as useRuntimeConfig, m as getResponseStatusText, n as getResponseStatus, o as defineRenderHandler, q as publicAssetsURL, r as getQuery, t as createError, v as destr, x as getRouteRules, j as joinURL, y as useNitroApp } from '../nitro/nitro.mjs';
|
||||
import { renderToString } from 'vue/server-renderer';
|
||||
import { createHead as createHead$1, propsToString, renderSSRHead } from 'unhead/server';
|
||||
import { stringify, uneval } from 'devalue';
|
||||
import { isRef, toValue } from 'vue';
|
||||
import 'node:http';
|
||||
import 'node:https';
|
||||
import 'node:events';
|
||||
import 'node:buffer';
|
||||
import 'node:fs';
|
||||
import 'node:path';
|
||||
import 'node:crypto';
|
||||
import 'node:url';
|
||||
import 'consola';
|
||||
import 'fast-xml-parser';
|
||||
import 'ipx';
|
||||
|
||||
const VueResolver = (_, value) => {
|
||||
return isRef(value) ? toValue(value) : value;
|
||||
};
|
||||
|
||||
const headSymbol = "usehead";
|
||||
// @__NO_SIDE_EFFECTS__
|
||||
function vueInstall(head) {
|
||||
const plugin = {
|
||||
install(app) {
|
||||
app.config.globalProperties.$unhead = head;
|
||||
app.config.globalProperties.$head = head;
|
||||
app.provide(headSymbol, head);
|
||||
}
|
||||
};
|
||||
return plugin.install;
|
||||
}
|
||||
|
||||
// @__NO_SIDE_EFFECTS__
|
||||
function createHead(options = {}) {
|
||||
const head = createHead$1({
|
||||
...options,
|
||||
propResolvers: [VueResolver]
|
||||
});
|
||||
head.install = vueInstall(head);
|
||||
return head;
|
||||
}
|
||||
|
||||
const NUXT_RUNTIME_PAYLOAD_EXTRACTION = false;
|
||||
|
||||
const appHead = {"meta":[{"name":"viewport","content":"width=device-width, initial-scale=1"},{"charset":"utf-8"},{"name":"screen-orientation","content":"portrait"}],"link":[{"rel":"manifest","href":"/manifest.webmanifest"}],"style":[],"script":[],"noscript":[],"title":"Loading..."};
|
||||
|
||||
const appRootTag = "div";
|
||||
|
||||
const appRootAttrs = {"id":"__nuxt"};
|
||||
|
||||
const appTeleportTag = "div";
|
||||
|
||||
const appTeleportAttrs = {"id":"teleports"};
|
||||
|
||||
const appSpaLoaderTag = "div";
|
||||
|
||||
const appSpaLoaderAttrs = {"id":"__nuxt-loader"};
|
||||
|
||||
const appId = "nuxt-app";
|
||||
|
||||
const APP_ROOT_OPEN_TAG = `<${appRootTag}${propsToString(appRootAttrs)}>`;
|
||||
const APP_ROOT_CLOSE_TAG = `</${appRootTag}>`;
|
||||
// @ts-expect-error file will be produced after app build
|
||||
const getServerEntry = () => import('../build/server.mjs').then(function (n) { return n.bI; }).then((r) => r.default || r);
|
||||
// @ts-expect-error file will be produced after app build
|
||||
const getPrecomputedDependencies = () => import('../build/client.precomputed.mjs').then((r) => r.default || r).then((r) => typeof r === "function" ? r() : r);
|
||||
// -- SSR Renderer --
|
||||
const getSSRRenderer = lazyCachedFunction(async () => {
|
||||
// Load server bundle
|
||||
const createSSRApp = await getServerEntry();
|
||||
if (!createSSRApp) {
|
||||
throw new Error("Server bundle is not available");
|
||||
}
|
||||
// Load precomputed dependencies
|
||||
const precomputed = await getPrecomputedDependencies();
|
||||
// Create renderer
|
||||
const renderer = createRenderer(createSSRApp, {
|
||||
precomputed,
|
||||
manifest: undefined,
|
||||
renderToString: renderToString$1,
|
||||
buildAssetsURL
|
||||
});
|
||||
async function renderToString$1(input, context) {
|
||||
const html = await renderToString(input, context);
|
||||
return APP_ROOT_OPEN_TAG + html + APP_ROOT_CLOSE_TAG;
|
||||
}
|
||||
return renderer;
|
||||
});
|
||||
// -- SPA Renderer --
|
||||
const getSPARenderer = lazyCachedFunction(async () => {
|
||||
const precomputed = await getPrecomputedDependencies();
|
||||
// @ts-expect-error virtual file
|
||||
const spaTemplate = await import('../virtual/_virtual_spa-template.mjs').then((r) => r.template).catch(() => "").then((r) => {
|
||||
{
|
||||
const APP_SPA_LOADER_OPEN_TAG = `<${appSpaLoaderTag}${propsToString(appSpaLoaderAttrs)}>`;
|
||||
const APP_SPA_LOADER_CLOSE_TAG = `</${appSpaLoaderTag}>`;
|
||||
const appTemplate = APP_ROOT_OPEN_TAG + APP_ROOT_CLOSE_TAG;
|
||||
const loaderTemplate = r ? APP_SPA_LOADER_OPEN_TAG + r + APP_SPA_LOADER_CLOSE_TAG : "";
|
||||
return appTemplate + loaderTemplate;
|
||||
}
|
||||
});
|
||||
// Create SPA renderer and cache the result for all requests
|
||||
const renderer = createRenderer(() => () => {}, {
|
||||
precomputed,
|
||||
manifest: undefined,
|
||||
renderToString: () => spaTemplate,
|
||||
buildAssetsURL
|
||||
});
|
||||
const result = await renderer.renderToString({});
|
||||
const renderToString = (ssrContext) => {
|
||||
const config = useRuntimeConfig(ssrContext.event);
|
||||
ssrContext.modules ||= new Set();
|
||||
ssrContext.payload.serverRendered = false;
|
||||
ssrContext.config = {
|
||||
public: config.public,
|
||||
app: config.app
|
||||
};
|
||||
return Promise.resolve(result);
|
||||
};
|
||||
return {
|
||||
rendererContext: renderer.rendererContext,
|
||||
renderToString
|
||||
};
|
||||
});
|
||||
function lazyCachedFunction(fn) {
|
||||
let res = null;
|
||||
return () => {
|
||||
if (res === null) {
|
||||
res = fn().catch((err) => {
|
||||
res = null;
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
return res;
|
||||
};
|
||||
}
|
||||
function getRenderer(ssrContext) {
|
||||
return ssrContext.noSSR ? getSPARenderer() : getSSRRenderer();
|
||||
}
|
||||
|
||||
function renderPayloadResponse(ssrContext) {
|
||||
return {
|
||||
body: stringify(splitPayload(ssrContext).payload, ssrContext["~payloadReducers"]) ,
|
||||
statusCode: getResponseStatus(ssrContext.event),
|
||||
statusMessage: getResponseStatusText(ssrContext.event),
|
||||
headers: {
|
||||
"content-type": "application/json;charset=utf-8" ,
|
||||
"x-powered-by": "Nuxt"
|
||||
}
|
||||
};
|
||||
}
|
||||
function renderPayloadJsonScript(opts) {
|
||||
const contents = opts.data ? stringify(opts.data, opts.ssrContext["~payloadReducers"]) : "";
|
||||
const payload = {
|
||||
"type": "application/json",
|
||||
"innerHTML": contents,
|
||||
"data-nuxt-data": appId,
|
||||
"data-ssr": !(opts.ssrContext.noSSR)
|
||||
};
|
||||
{
|
||||
payload.id = "__NUXT_DATA__";
|
||||
}
|
||||
if (opts.src) {
|
||||
payload["data-src"] = opts.src;
|
||||
}
|
||||
const config = uneval(opts.ssrContext.config);
|
||||
return [payload, { innerHTML: `window.__NUXT__={};window.__NUXT__.config=${config}` }];
|
||||
}
|
||||
function splitPayload(ssrContext) {
|
||||
const { data, prerenderedAt, ...initial } = ssrContext.payload;
|
||||
return {
|
||||
initial: {
|
||||
...initial,
|
||||
prerenderedAt
|
||||
},
|
||||
payload: {
|
||||
data,
|
||||
prerenderedAt
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const unheadOptions = {
|
||||
disableDefaults: true,
|
||||
};
|
||||
|
||||
function createSSRContext(event) {
|
||||
const ssrContext = {
|
||||
url: event.path,
|
||||
event,
|
||||
runtimeConfig: useRuntimeConfig(event),
|
||||
noSSR: event.context.nuxt?.noSSR || (false),
|
||||
head: createHead(unheadOptions),
|
||||
error: false,
|
||||
nuxt: undefined,
|
||||
payload: {},
|
||||
["~payloadReducers"]: Object.create(null),
|
||||
modules: new Set()
|
||||
};
|
||||
return ssrContext;
|
||||
}
|
||||
function setSSRError(ssrContext, error) {
|
||||
ssrContext.error = true;
|
||||
ssrContext.payload = { error };
|
||||
ssrContext.url = error.url;
|
||||
}
|
||||
|
||||
const renderSSRHeadOptions = {"omitLineBreaks":true};
|
||||
|
||||
// @ts-expect-error private property consumed by vite-generated url helpers
|
||||
globalThis.__buildAssetsURL = buildAssetsURL;
|
||||
// @ts-expect-error private property consumed by vite-generated url helpers
|
||||
globalThis.__publicAssetsURL = publicAssetsURL;
|
||||
const HAS_APP_TELEPORTS = !!(appTeleportAttrs.id);
|
||||
const APP_TELEPORT_OPEN_TAG = HAS_APP_TELEPORTS ? `<${appTeleportTag}${propsToString(appTeleportAttrs)}>` : "";
|
||||
const APP_TELEPORT_CLOSE_TAG = HAS_APP_TELEPORTS ? `</${appTeleportTag}>` : "";
|
||||
const PAYLOAD_URL_RE = /^[^?]*\/_payload.json(?:\?.*)?$/ ;
|
||||
const PAYLOAD_FILENAME = "_payload.json" ;
|
||||
const renderer = defineRenderHandler(async (event) => {
|
||||
const nitroApp = useNitroApp();
|
||||
// Whether we're rendering an error page
|
||||
const ssrError = event.path.startsWith("/__nuxt_error") ? getQuery(event) : null;
|
||||
if (ssrError && !("__unenv__" in event.node.req)) {
|
||||
throw createError({
|
||||
status: 404,
|
||||
statusText: "Page Not Found: /__nuxt_error",
|
||||
message: "Page Not Found: /__nuxt_error"
|
||||
});
|
||||
}
|
||||
// Initialize ssr context
|
||||
const ssrContext = createSSRContext(event);
|
||||
// needed for hash hydration plugin to work
|
||||
const headEntryOptions = { mode: "server" };
|
||||
ssrContext.head.push(appHead, headEntryOptions);
|
||||
if (ssrError) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
||||
const status = ssrError.status || ssrError.statusCode;
|
||||
if (status) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
||||
ssrError.status = ssrError.statusCode = Number.parseInt(status);
|
||||
}
|
||||
if (typeof ssrError.data === "string") {
|
||||
try {
|
||||
ssrError.data = destr(ssrError.data);
|
||||
} catch {}
|
||||
}
|
||||
setSSRError(ssrContext, ssrError);
|
||||
}
|
||||
// Get route options (for `ssr: false`, `isr`, `cache` and `noScripts`)
|
||||
const routeOptions = getRouteRules(event);
|
||||
// Whether we are prerendering route or using ISR/SWR caching
|
||||
const _PAYLOAD_EXTRACTION = !ssrContext.noSSR && (NUXT_RUNTIME_PAYLOAD_EXTRACTION);
|
||||
const isRenderingPayload = (_PAYLOAD_EXTRACTION || false) && PAYLOAD_URL_RE.test(ssrContext.url);
|
||||
if (isRenderingPayload) {
|
||||
const url = ssrContext.url.substring(0, ssrContext.url.lastIndexOf("/")) || "/";
|
||||
ssrContext.url = url;
|
||||
event._path = event.node.req.url = url;
|
||||
}
|
||||
if (routeOptions.ssr === false) {
|
||||
ssrContext.noSSR = true;
|
||||
}
|
||||
const payloadURL = _PAYLOAD_EXTRACTION ? joinURL(ssrContext.runtimeConfig.app.cdnURL || ssrContext.runtimeConfig.app.baseURL, ssrContext.url.replace(/\?.*$/, ""), PAYLOAD_FILENAME) + "?" + ssrContext.runtimeConfig.app.buildId : undefined;
|
||||
// Render app
|
||||
const renderer = await getRenderer(ssrContext);
|
||||
const _rendered = await renderer.renderToString(ssrContext).catch(async (error) => {
|
||||
// We use error to bypass full render if we have an early response we can make
|
||||
// TODO: remove _renderResponse in nuxt v5
|
||||
if ((ssrContext["~renderResponse"] || ssrContext._renderResponse) && error.message === "skipping render") {
|
||||
return {};
|
||||
}
|
||||
// Use explicitly thrown error in preference to subsequent rendering errors
|
||||
const _err = !ssrError && ssrContext.payload?.error || error;
|
||||
await ssrContext.nuxt?.hooks.callHook("app:error", _err);
|
||||
throw _err;
|
||||
});
|
||||
// Render inline styles
|
||||
// TODO: remove _renderResponse in nuxt v5
|
||||
const inlinedStyles = [];
|
||||
await ssrContext.nuxt?.hooks.callHook("app:rendered", {
|
||||
ssrContext,
|
||||
renderResult: _rendered
|
||||
});
|
||||
if (ssrContext["~renderResponse"] || ssrContext._renderResponse) {
|
||||
// TODO: remove _renderResponse in nuxt v5
|
||||
return ssrContext["~renderResponse"] || ssrContext._renderResponse;
|
||||
}
|
||||
// Handle errors
|
||||
if (ssrContext.payload?.error && !ssrError) {
|
||||
throw ssrContext.payload.error;
|
||||
}
|
||||
// Directly render payload routes
|
||||
if (isRenderingPayload) {
|
||||
const response = renderPayloadResponse(ssrContext);
|
||||
return response;
|
||||
}
|
||||
const NO_SCRIPTS = routeOptions.noScripts;
|
||||
// Setup head
|
||||
const { styles, scripts } = getRequestDependencies(ssrContext, renderer.rendererContext);
|
||||
// 1. Preload payloads and app manifest
|
||||
if (_PAYLOAD_EXTRACTION && !NO_SCRIPTS) {
|
||||
ssrContext.head.push({ link: [{
|
||||
rel: "preload",
|
||||
as: "fetch",
|
||||
crossorigin: "anonymous",
|
||||
href: payloadURL
|
||||
} ] }, headEntryOptions);
|
||||
}
|
||||
if (ssrContext["~preloadManifest"] && !NO_SCRIPTS) {
|
||||
ssrContext.head.push({ link: [{
|
||||
rel: "preload",
|
||||
as: "fetch",
|
||||
fetchpriority: "low",
|
||||
crossorigin: "anonymous",
|
||||
href: buildAssetsURL(`builds/meta/${ssrContext.runtimeConfig.app.buildId}.json`)
|
||||
}] }, {
|
||||
...headEntryOptions,
|
||||
tagPriority: "low"
|
||||
});
|
||||
}
|
||||
// 2. Styles
|
||||
if (inlinedStyles.length) {
|
||||
ssrContext.head.push({ style: inlinedStyles });
|
||||
}
|
||||
const link = [];
|
||||
for (const resource of Object.values(styles)) {
|
||||
// Add CSS links in <head> for CSS files
|
||||
// - in production
|
||||
// - in dev mode when not rendering an island
|
||||
link.push({
|
||||
rel: "stylesheet",
|
||||
href: renderer.rendererContext.buildAssetsURL(resource.file),
|
||||
crossorigin: ""
|
||||
});
|
||||
}
|
||||
if (link.length) {
|
||||
ssrContext.head.push({ link }, headEntryOptions);
|
||||
}
|
||||
if (!NO_SCRIPTS) {
|
||||
// 4. Resource Hints
|
||||
// Remove lazy hydrated modules from ssrContext.modules so they don't get preloaded
|
||||
// (CSS links are already added above, this only affects JS preloads)
|
||||
if (ssrContext["~lazyHydratedModules"]) {
|
||||
for (const id of ssrContext["~lazyHydratedModules"]) {
|
||||
ssrContext.modules?.delete(id);
|
||||
}
|
||||
}
|
||||
ssrContext.head.push({ link: getPreloadLinks(ssrContext, renderer.rendererContext) }, headEntryOptions);
|
||||
ssrContext.head.push({ link: getPrefetchLinks(ssrContext, renderer.rendererContext) }, headEntryOptions);
|
||||
// 5. Payloads
|
||||
ssrContext.head.push({ script: _PAYLOAD_EXTRACTION ? renderPayloadJsonScript({
|
||||
ssrContext,
|
||||
data: splitPayload(ssrContext).initial,
|
||||
src: payloadURL
|
||||
}) : renderPayloadJsonScript({
|
||||
ssrContext,
|
||||
data: ssrContext.payload
|
||||
}) }, {
|
||||
...headEntryOptions,
|
||||
tagPosition: "bodyClose",
|
||||
tagPriority: "high"
|
||||
});
|
||||
}
|
||||
// 6. Scripts
|
||||
if (!routeOptions.noScripts) {
|
||||
const tagPosition = "head";
|
||||
ssrContext.head.push({ script: Object.values(scripts).map((resource) => ({
|
||||
type: resource.module ? "module" : null,
|
||||
src: renderer.rendererContext.buildAssetsURL(resource.file),
|
||||
defer: resource.module ? null : true,
|
||||
tagPosition,
|
||||
crossorigin: ""
|
||||
})) }, headEntryOptions);
|
||||
}
|
||||
const { headTags, bodyTags, bodyTagsOpen, htmlAttrs, bodyAttrs } = await renderSSRHead(ssrContext.head, renderSSRHeadOptions);
|
||||
// Create render context
|
||||
const htmlContext = {
|
||||
htmlAttrs: htmlAttrs ? [htmlAttrs] : [],
|
||||
head: normalizeChunks([headTags]),
|
||||
bodyAttrs: bodyAttrs ? [bodyAttrs] : [],
|
||||
bodyPrepend: normalizeChunks([bodyTagsOpen, ssrContext.teleports?.body]),
|
||||
body: [_rendered.html, APP_TELEPORT_OPEN_TAG + (HAS_APP_TELEPORTS ? joinTags([ssrContext.teleports?.[`#${appTeleportAttrs.id}`]]) : "") + APP_TELEPORT_CLOSE_TAG],
|
||||
bodyAppend: [bodyTags]
|
||||
};
|
||||
// Allow hooking into the rendered result
|
||||
await nitroApp.hooks.callHook("render:html", htmlContext, { event });
|
||||
// Construct HTML response
|
||||
return {
|
||||
body: renderHTMLDocument(htmlContext),
|
||||
statusCode: getResponseStatus(event),
|
||||
statusMessage: getResponseStatusText(event),
|
||||
headers: {
|
||||
"content-type": "text/html;charset=utf-8",
|
||||
"x-powered-by": "Nuxt"
|
||||
}
|
||||
};
|
||||
});
|
||||
function normalizeChunks(chunks) {
|
||||
const result = [];
|
||||
for (const _chunk of chunks) {
|
||||
const chunk = _chunk?.trim();
|
||||
if (chunk) {
|
||||
result.push(chunk);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function joinTags(tags) {
|
||||
return tags.join("");
|
||||
}
|
||||
function joinAttrs(chunks) {
|
||||
if (chunks.length === 0) {
|
||||
return "";
|
||||
}
|
||||
return " " + chunks.join(" ");
|
||||
}
|
||||
function renderHTMLDocument(html) {
|
||||
return "<!DOCTYPE html>" + `<html${joinAttrs(html.htmlAttrs)}>` + `<head>${joinTags(html.head)}</head>` + `<body${joinAttrs(html.bodyAttrs)}>${joinTags(html.bodyPrepend)}${joinTags(html.body)}${joinTags(html.bodyAppend)}</body>` + "</html>";
|
||||
}
|
||||
|
||||
export { renderer as default };
|
||||
Reference in New Issue
Block a user