MCPcopy
hub / github.com/sveltejs/kit / serve_prerendered

Function serve_prerendered

packages/adapter-node/src/handler.js:67–92  ·  view source on GitHub ↗

@returns {import('polka').Middleware}

()

Source from the content-addressed store, hash-verified

65// required because the static file server ignores trailing slashes
66/** @returns {import('polka').Middleware} */
67function serve_prerendered() {
68 const handler = serve(path.join(dir, 'prerendered'));
69
70 return (req, res, next) => {
71 let { pathname, search, query } = polka_url_parser(req);
72
73 try {
74 pathname = decodeURIComponent(pathname);
75 } catch {
76 // ignore invalid URI
77 }
78
79 if (prerendered.has(pathname)) {
80 return handler(req, res, next);
81 }
82
83 // remove or add trailing slash as appropriate
84 let location = pathname.at(-1) === '/' ? pathname.slice(0, -1) : pathname + '/';
85 if (prerendered.has(location)) {
86 if (query) location += search;
87 res.writeHead(308, { location }).end();
88 } else {
89 void next();
90 }
91 };
92}
93
94/** @type {import('polka').Middleware} */
95const ssr = async (req, res) => {

Callers 1

handler.jsFile · 0.85

Calls 3

serveFunction · 0.85
nextFunction · 0.85
handlerFunction · 0.50

Tested by

no test coverage detected