You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
367 lines
13 KiB
367 lines
13 KiB
import process from 'node:process';globalThis._importMeta_=globalThis._importMeta_||{url:"file:///_entry.js",env:process.env};import { getRequestDependencies, getPreloadLinks, getPrefetchLinks, createRenderer } from 'vue-bundle-renderer/runtime';
|
|
import { u as useRuntimeConfig, e as eventHandler, s as setResponseHeader, a as send, g as getResponseStatus, b as setResponseStatus, c as useNitroApp, d as setResponseHeaders, j as joinRelativeURL, f as getQuery, h as createError, i as getRouteRules, k as getResponseStatusText } from '../runtime.mjs';
|
|
import { stringify, uneval } from 'devalue';
|
|
import { propsToString, renderSSRHead } from '@unhead/ssr';
|
|
import { createServerHead as createServerHead$1, CapoPlugin } from 'unhead';
|
|
import { version, unref } from 'vue';
|
|
import { defineHeadPlugin } from '@unhead/shared';
|
|
import 'node:http';
|
|
import 'node:https';
|
|
import 'fs';
|
|
import 'path';
|
|
import 'node:fs';
|
|
import 'node:url';
|
|
import 'ipx';
|
|
|
|
function defineRenderHandler(handler) {
|
|
const runtimeConfig = useRuntimeConfig();
|
|
return eventHandler(async (event) => {
|
|
if (event.path === `${runtimeConfig.app.baseURL}favicon.ico`) {
|
|
setResponseHeader(event, "Content-Type", "image/x-icon");
|
|
return send(
|
|
event,
|
|
"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
|
|
);
|
|
}
|
|
const response = await handler(event);
|
|
if (!response) {
|
|
const _currentStatus = getResponseStatus(event);
|
|
setResponseStatus(event, _currentStatus === 200 ? 500 : _currentStatus);
|
|
return send(
|
|
event,
|
|
"No response returned from render handler: " + event.path
|
|
);
|
|
}
|
|
const nitroApp = useNitroApp();
|
|
await nitroApp.hooks.callHook("render:response", response, { event });
|
|
if (response.headers) {
|
|
setResponseHeaders(event, response.headers);
|
|
}
|
|
if (response.statusCode || response.statusMessage) {
|
|
setResponseStatus(event, response.statusCode, response.statusMessage);
|
|
}
|
|
return response.body;
|
|
});
|
|
}
|
|
|
|
function buildAssetsDir() {
|
|
return useRuntimeConfig().app.buildAssetsDir;
|
|
}
|
|
function buildAssetsURL(...path) {
|
|
return joinRelativeURL(publicAssetsURL(), buildAssetsDir(), ...path);
|
|
}
|
|
function publicAssetsURL(...path) {
|
|
const app = useRuntimeConfig().app;
|
|
const publicBase = app.cdnURL || app.baseURL;
|
|
return path.length ? joinRelativeURL(publicBase, ...path) : publicBase;
|
|
}
|
|
|
|
const Vue3 = version[0] === "3";
|
|
|
|
function resolveUnref(r) {
|
|
return typeof r === "function" ? r() : unref(r);
|
|
}
|
|
function resolveUnrefHeadInput(ref) {
|
|
if (ref instanceof Promise)
|
|
return ref;
|
|
const root = resolveUnref(ref);
|
|
if (!ref || !root)
|
|
return root;
|
|
if (Array.isArray(root))
|
|
return root.map((r) => resolveUnrefHeadInput(r));
|
|
if (typeof root === "object") {
|
|
const resolved = {};
|
|
for (const k in root) {
|
|
if (!Object.prototype.hasOwnProperty.call(root, k)) {
|
|
continue;
|
|
}
|
|
if (k === "titleTemplate" || k[0] === "o" && k[1] === "n") {
|
|
resolved[k] = unref(root[k]);
|
|
continue;
|
|
}
|
|
resolved[k] = resolveUnrefHeadInput(root[k]);
|
|
}
|
|
return resolved;
|
|
}
|
|
return root;
|
|
}
|
|
|
|
const VueReactivityPlugin = defineHeadPlugin({
|
|
hooks: {
|
|
"entries:resolve": (ctx) => {
|
|
for (const entry of ctx.entries)
|
|
entry.resolvedInput = resolveUnrefHeadInput(entry.input);
|
|
}
|
|
}
|
|
});
|
|
|
|
const headSymbol = "usehead";
|
|
function vueInstall(head) {
|
|
const plugin = {
|
|
install(app) {
|
|
if (Vue3) {
|
|
app.config.globalProperties.$unhead = head;
|
|
app.config.globalProperties.$head = head;
|
|
app.provide(headSymbol, head);
|
|
}
|
|
}
|
|
};
|
|
return plugin.install;
|
|
}
|
|
function createServerHead(options = {}) {
|
|
const head = createServerHead$1(options);
|
|
head.use(VueReactivityPlugin);
|
|
head.install = vueInstall(head);
|
|
return head;
|
|
}
|
|
|
|
const unheadPlugins = true ? [CapoPlugin({ track: true })] : [];
|
|
|
|
const renderSSRHeadOptions = {"omitLineBreaks":false};
|
|
|
|
const appHead = {"meta":[{"name":"viewport","content":"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"},{"charset":"utf-8"},{"name":"keywords","content":"云·企业官网,云cms,建站系统,网站源码,java,nuxt,antd,vue3"},{"name":"description","content":"weSite企业建站系统,助力企业信息化建设和转型,主要产品有:企业官网,电商系统,微信公众号,微信小程序应用等,使用目前最流行的技术栈打造。https://websoft.top"}],"link":[{"rel":"icon","type":"image/x-icon","href":"/favicon.ico"}],"style":[],"script":[],"noscript":[],"title":"云·企业官网","viewport":"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"};
|
|
|
|
const appRootTag = "div";
|
|
|
|
const appRootAttrs = {"id":"__nuxt"};
|
|
|
|
const appTeleportTag = "div";
|
|
|
|
const appTeleportAttrs = {"id":"teleports"};
|
|
|
|
const componentIslands = false;
|
|
|
|
globalThis.__buildAssetsURL = buildAssetsURL;
|
|
globalThis.__publicAssetsURL = publicAssetsURL;
|
|
const getClientManifest = () => import('../build/client.manifest.mjs').then((r) => r.default || r).then((r) => typeof r === "function" ? r() : r);
|
|
const getSPARenderer = lazyCachedFunction(async () => {
|
|
const manifest = await getClientManifest();
|
|
const spaTemplate = await import('../virtual/_virtual_spa-template.mjs').then((r) => r.template).catch(() => "").then((r) => APP_ROOT_OPEN_TAG + r + APP_ROOT_CLOSE_TAG);
|
|
const options = {
|
|
manifest,
|
|
renderToString: () => spaTemplate,
|
|
buildAssetsURL
|
|
};
|
|
const renderer = createRenderer(() => () => {
|
|
}, options);
|
|
const result = await renderer.renderToString({});
|
|
const renderToString = (ssrContext) => {
|
|
const config = useRuntimeConfig(ssrContext.event);
|
|
ssrContext.modules = ssrContext.modules || /* @__PURE__ */ new Set();
|
|
ssrContext.payload = {
|
|
serverRendered: false
|
|
};
|
|
ssrContext.config = {
|
|
public: config.public,
|
|
app: config.app
|
|
};
|
|
return Promise.resolve(result);
|
|
};
|
|
return {
|
|
rendererContext: renderer.rendererContext,
|
|
renderToString
|
|
};
|
|
});
|
|
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 APP_ROOT_OPEN_TAG = `<${appRootTag}${propsToString(appRootAttrs)}>`;
|
|
const APP_ROOT_CLOSE_TAG = `</${appRootTag}>`;
|
|
const PAYLOAD_URL_RE = /\/_payload.json(\?.*)?$/ ;
|
|
const renderer = defineRenderHandler(async (event) => {
|
|
const nitroApp = useNitroApp();
|
|
const ssrError = event.path.startsWith("/__nuxt_error") ? getQuery(event) : null;
|
|
if (ssrError && ssrError.statusCode) {
|
|
ssrError.statusCode = Number.parseInt(ssrError.statusCode);
|
|
}
|
|
if (ssrError && !("__unenv__" in event.node.req)) {
|
|
throw createError({
|
|
statusCode: 404,
|
|
statusMessage: "Page Not Found: /__nuxt_error"
|
|
});
|
|
}
|
|
const isRenderingIsland = componentIslands;
|
|
const islandContext = void 0;
|
|
let url = ssrError?.url || islandContext?.url || event.path;
|
|
const isRenderingPayload = PAYLOAD_URL_RE.test(url) && !isRenderingIsland;
|
|
if (isRenderingPayload) {
|
|
url = url.substring(0, url.lastIndexOf("/")) || "/";
|
|
event._path = url;
|
|
event.node.req.url = url;
|
|
}
|
|
const routeOptions = getRouteRules(event);
|
|
const head = createServerHead({
|
|
plugins: unheadPlugins
|
|
});
|
|
const headEntryOptions = { mode: "server" };
|
|
{
|
|
head.push(appHead, headEntryOptions);
|
|
}
|
|
const ssrContext = {
|
|
url,
|
|
event,
|
|
runtimeConfig: useRuntimeConfig(event),
|
|
noSSR: !!true,
|
|
head,
|
|
error: !!ssrError,
|
|
nuxt: void 0,
|
|
/* NuxtApp */
|
|
payload: ssrError ? { error: ssrError } : {},
|
|
_payloadReducers: {},
|
|
modules: /* @__PURE__ */ new Set(),
|
|
islandContext
|
|
};
|
|
const renderer = await getSPARenderer() ;
|
|
const _rendered = await renderer.renderToString(ssrContext).catch(async (error) => {
|
|
if (ssrContext._renderResponse && error.message === "skipping render") {
|
|
return {};
|
|
}
|
|
const _err = !ssrError && ssrContext.payload?.error || error;
|
|
await ssrContext.nuxt?.hooks.callHook("app:error", _err);
|
|
throw _err;
|
|
});
|
|
await ssrContext.nuxt?.hooks.callHook("app:rendered", { ssrContext, renderResult: _rendered });
|
|
if (ssrContext._renderResponse) {
|
|
return ssrContext._renderResponse;
|
|
}
|
|
if (ssrContext.payload?.error && !ssrError) {
|
|
throw ssrContext.payload.error;
|
|
}
|
|
if (isRenderingPayload) {
|
|
const response2 = renderPayloadResponse(ssrContext);
|
|
return response2;
|
|
}
|
|
const inlinedStyles = [];
|
|
const NO_SCRIPTS = routeOptions.experimentalNoScripts;
|
|
const { styles, scripts } = getRequestDependencies(ssrContext, renderer.rendererContext);
|
|
head.push({ style: inlinedStyles });
|
|
{
|
|
const link = [];
|
|
for (const style in styles) {
|
|
const resource = styles[style];
|
|
{
|
|
link.push({ rel: "stylesheet", href: renderer.rendererContext.buildAssetsURL(resource.file) });
|
|
}
|
|
}
|
|
head.push({ link }, headEntryOptions);
|
|
}
|
|
if (!NO_SCRIPTS && !isRenderingIsland) {
|
|
head.push({
|
|
link: getPreloadLinks(ssrContext, renderer.rendererContext)
|
|
}, headEntryOptions);
|
|
head.push({
|
|
link: getPrefetchLinks(ssrContext, renderer.rendererContext)
|
|
}, headEntryOptions);
|
|
head.push({
|
|
script: renderPayloadJsonScript({ id: "__NUXT_DATA__", ssrContext, data: ssrContext.payload })
|
|
}, {
|
|
...headEntryOptions,
|
|
// this should come before another end of body scripts
|
|
tagPosition: "bodyClose",
|
|
tagPriority: "high"
|
|
});
|
|
}
|
|
if (!routeOptions.experimentalNoScripts && !isRenderingIsland) {
|
|
head.push({
|
|
script: Object.values(scripts).map((resource) => ({
|
|
type: resource.module ? "module" : null,
|
|
src: renderer.rendererContext.buildAssetsURL(resource.file),
|
|
defer: resource.module ? null : true,
|
|
// if we are rendering script tag payloads that import an async payload
|
|
// we need to ensure this resolves before executing the Nuxt entry
|
|
tagPosition: "head",
|
|
crossorigin: ""
|
|
}))
|
|
}, headEntryOptions);
|
|
}
|
|
const { headTags, bodyTags, bodyTagsOpen, htmlAttrs, bodyAttrs } = await renderSSRHead(head, renderSSRHeadOptions);
|
|
const htmlContext = {
|
|
island: isRenderingIsland,
|
|
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]
|
|
};
|
|
await nitroApp.hooks.callHook("render:html", htmlContext, { event });
|
|
const response = {
|
|
body: renderHTMLDocument(htmlContext),
|
|
statusCode: getResponseStatus(event),
|
|
statusMessage: getResponseStatusText(event),
|
|
headers: {
|
|
"content-type": "text/html;charset=utf-8",
|
|
"x-powered-by": "Nuxt"
|
|
}
|
|
};
|
|
return response;
|
|
});
|
|
function lazyCachedFunction(fn) {
|
|
let res = null;
|
|
return () => {
|
|
if (res === null) {
|
|
res = fn().catch((err) => {
|
|
res = null;
|
|
throw err;
|
|
});
|
|
}
|
|
return res;
|
|
};
|
|
}
|
|
function normalizeChunks(chunks) {
|
|
return chunks.filter(Boolean).map((i) => i.trim());
|
|
}
|
|
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>`;
|
|
}
|
|
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",
|
|
"id": opts.id,
|
|
"innerHTML": contents,
|
|
"data-ssr": !(true)
|
|
};
|
|
if (opts.src) {
|
|
payload["data-src"] = opts.src;
|
|
}
|
|
return [
|
|
payload,
|
|
{
|
|
innerHTML: `window.__NUXT__={};window.__NUXT__.config=${uneval(opts.ssrContext.config)}`
|
|
}
|
|
];
|
|
}
|
|
function splitPayload(ssrContext) {
|
|
const { data, prerenderedAt, ...initial } = ssrContext.payload;
|
|
return {
|
|
initial: { ...initial, prerenderedAt },
|
|
payload: { data, prerenderedAt }
|
|
};
|
|
}
|
|
|
|
export { renderer as default };
|
|
//# sourceMappingURL=renderer.mjs.map
|