@sveltejs/adapter-cloudflare
Advanced tools
Comparing version 1.0.0-next.16 to 1.0.0-next.17
@@ -1,63 +0,73 @@ | ||
import { Server } from 'SERVER'; | ||
import { manifest, prerendered } from 'MANIFEST'; | ||
// src/worker.js | ||
import { Server } from "SERVER"; | ||
import { manifest, prerendered } from "MANIFEST"; | ||
const server = new Server(manifest); | ||
// ../../node_modules/.pnpm/worktop@0.8.0-next.12/node_modules/worktop/cache/index.mjs | ||
async function o(n2, e) { | ||
let t = typeof e != "string" && e.method === "HEAD"; | ||
t && (e = new Request(e, { method: "GET" })); | ||
let a = await n2.match(e); | ||
return t && a && (a = new Response(null, a)), a; | ||
} | ||
function r(n2, e, t, a) { | ||
return (typeof e == "string" || e.method === "GET") && f(t) && (t.headers.has("Set-Cookie") && (t = new Response(t.body, t), t.headers.append("Cache-Control", "private=Set-Cookie")), a.waitUntil(n2.put(e, t.clone()))), t; | ||
} | ||
function f(n2) { | ||
if (n2.status === 101 || n2.status === 206 || ~(n2.headers.get("Vary") || "").indexOf("*")) | ||
return false; | ||
let t = n2.headers.get("Cache-Control") || ""; | ||
return !/(private|no-cache|no-store)/i.test(t); | ||
} | ||
const prefix = `/${manifest.appDir}/`; | ||
// ../../node_modules/.pnpm/worktop@0.8.0-next.12/node_modules/worktop/cfw.cache/index.mjs | ||
var o2 = caches.default; | ||
var s = /* @__PURE__ */ r.bind(0, o2); | ||
var n = /* @__PURE__ */ o.bind(0, o2); | ||
export default { | ||
/** | ||
* @param {Request} req | ||
* @param {any} env | ||
* @param {any} context | ||
*/ | ||
async fetch(req, env, context) { | ||
const url = new URL(req.url); | ||
// static assets | ||
if (url.pathname.startsWith(prefix)) { | ||
/** @type {Response} */ | ||
const res = await env.ASSETS.fetch(req); | ||
return new Response(res.body, { | ||
headers: { | ||
// include original cache headers, minus cache-control which | ||
// is overridden, and etag which is no longer useful | ||
'cache-control': 'public, immutable, max-age=31536000', | ||
'content-type': res.headers.get('content-type'), | ||
'x-robots-tag': 'noindex' | ||
} | ||
}); | ||
} | ||
// prerendered pages and index.html files | ||
const pathname = url.pathname.replace(/\/$/, ''); | ||
let file = pathname.substring(1); | ||
try { | ||
file = decodeURIComponent(file); | ||
} catch (err) { | ||
// ignore | ||
} | ||
if ( | ||
manifest.assets.has(file) || | ||
manifest.assets.has(file + '/index.html') || | ||
prerendered.has(pathname || '/') | ||
) { | ||
return env.ASSETS.fetch(req); | ||
} | ||
// dynamically-generated pages | ||
try { | ||
return await server.respond(req, { | ||
platform: { env, context }, | ||
getClientAddress() { | ||
return req.headers.get('cf-connecting-ip'); | ||
} | ||
}); | ||
} catch (e) { | ||
return new Response('Error rendering route: ' + (e.message || e.toString()), { status: 500 }); | ||
} | ||
} | ||
// src/worker.js | ||
var server = new Server(manifest); | ||
var prefix = `/${manifest.appDir}/`; | ||
var worker = { | ||
async fetch(req, env, context) { | ||
try { | ||
let res = await n(req); | ||
if (res) | ||
return res; | ||
let { pathname } = new URL(req.url); | ||
if (pathname.startsWith(prefix)) { | ||
res = await env.ASSETS.fetch(req); | ||
res = new Response(res.body, { | ||
headers: { | ||
"cache-control": "public, immutable, max-age=31536000", | ||
"content-type": res.headers.get("content-type"), | ||
"x-robots-tag": "noindex" | ||
} | ||
}); | ||
} else { | ||
pathname = pathname.replace(/\/$/, "") || "/"; | ||
let file = pathname.substring(1); | ||
try { | ||
file = decodeURIComponent(file); | ||
} catch (err) { | ||
} | ||
if (manifest.assets.has(file) || manifest.assets.has(file + "/index.html") || prerendered.has(pathname)) { | ||
res = await env.ASSETS.fetch(req); | ||
} else { | ||
res = await server.respond(req, { | ||
platform: { env, context }, | ||
getClientAddress() { | ||
return req.headers.get("cf-connecting-ip"); | ||
} | ||
}); | ||
} | ||
} | ||
return s(req, res, context); | ||
} catch (e) { | ||
return new Response("Error rendering route: " + (e.message || e.toString()), { status: 500 }); | ||
} | ||
} | ||
}; | ||
var worker_default = worker; | ||
export { | ||
worker_default as default | ||
}; |
{ | ||
"name": "@sveltejs/adapter-cloudflare", | ||
"version": "1.0.0-next.16", | ||
"version": "1.0.0-next.17", | ||
"repository": { | ||
@@ -26,5 +26,7 @@ "type": "git", | ||
"dependencies": { | ||
"esbuild": "^0.14.21" | ||
"esbuild": "^0.14.21", | ||
"worktop": "0.8.0-next.12" | ||
}, | ||
"devDependencies": { | ||
"@types/ws": "^8.5.3", | ||
"typescript": "^4.6.2" | ||
@@ -36,7 +38,8 @@ }, | ||
"scripts": { | ||
"build": "esbuild src/worker.js --bundle --outfile=files/worker.js --external:SERVER --external:MANIFEST --format=esm", | ||
"lint": "eslint --ignore-path .gitignore \"**/*.{ts,js,svelte}\" && npm run check-format", | ||
"format": "npm run check-format -- --write", | ||
"check": "tsc", | ||
"check": "tsc --skipLibCheck", | ||
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9372
117
2
2
+ Addedworktop@0.8.0-next.12
+ Addedmrmime@1.0.1(transitive)
+ Addedregexparam@2.0.2(transitive)
+ Addedworktop@0.8.0-next.12(transitive)