wrangler
Advanced tools
Comparing version 0.0.0-5a865ab to 0.0.0-6937fe9
@@ -1,2 +0,36 @@ | ||
#!/usr/bin/env node --no-warnings | ||
require("../wrangler-dist/index_node.js"); | ||
#!/usr/bin/env node | ||
const { spawn } = require("child_process"); | ||
const { join } = require("path"); | ||
const semiver = require("semiver"); | ||
const MIN_NODE_VERSION = "16.7.0"; | ||
async function main() { | ||
if (semiver(process.versions.node, MIN_NODE_VERSION) < 0) { | ||
// Note Volta and nvm are also recommended in the official docs: | ||
// https://developers.cloudflare.com/workers/get-started/guide#2-install-the-workers-cli | ||
console.error( | ||
`Wrangler requires at least Node.js ${MIN_NODE_VERSION}. | ||
You should use the latest Node.js version if possible, as Cloudflare Workers use a very up-to-date version of V8. | ||
Consider using a Node.js version manager such as https://volta.sh/ or https://github.com/nvm-sh/nvm.` | ||
); | ||
process.exit(1); | ||
return; | ||
} | ||
spawn( | ||
process.execPath, | ||
[ | ||
"--no-warnings", | ||
"--experimental-vm-modules", | ||
...process.execArgv, | ||
join(__dirname, "../wrangler-dist/index_node.js"), | ||
...process.argv.slice(2), | ||
], | ||
{ stdio: "inherit" } | ||
).on("exit", (code) => | ||
process.exit(code === undefined || code === null ? 0 : code) | ||
); | ||
} | ||
void main(); |
{ | ||
"name": "wrangler", | ||
"version": "0.0.0-5a865ab", | ||
"version": "0.0.0-6937fe9", | ||
"author": "wrangler@cloudflare.com", | ||
@@ -36,5 +36,5 @@ "description": "Command-line interface for all things Cloudflare Workers", | ||
"dependencies": { | ||
"esbuild": "^0.12.19", | ||
"miniflare": "^1.3.3", | ||
"yargs": "^17.1.1" | ||
"esbuild": "0.13.12", | ||
"miniflare": "2.0.0-rc.1", | ||
"semiver": "^1.1.0" | ||
}, | ||
@@ -47,26 +47,34 @@ "optionalDependencies": { | ||
"@types/cloudflare": "^2.7.6", | ||
"@types/react": "^17.0.19", | ||
"@types/react": "^17.0.34", | ||
"@types/signal-exit": "^3.0.1", | ||
"@types/ws": "^7.4.7", | ||
"@types/yargs": "^17.0.2", | ||
"clipboardy": "^2.3.0", | ||
"cloudflare": "^2.9.1", | ||
"find-up": "^6.0.0", | ||
"formdata-node": "^3.6.3", | ||
"@types/ws": "^8.2.0", | ||
"@types/yargs": "^17.0.5", | ||
"clipboardy": "^3.0.0", | ||
"command-exists": "^1.2.9", | ||
"execa": "^5.1.1", | ||
"finalhandler": "^1.1.2", | ||
"find-up": "^6.2.0", | ||
"formdata-node": "^4.3.1", | ||
"http-proxy": "^1.18.1", | ||
"ink": "^3.2.0", | ||
"ink-select-input": "^4.2.0", | ||
"ink-table": "^3.0.0", | ||
"ink-text-input": "^4.0.1", | ||
"node-fetch": "github:tekwiz/node-fetch#fix/redirect-with-empty-chunked-transfer-encoding", | ||
"open": "^8.2.1", | ||
"open": "^8.4.0", | ||
"react": "^17.0.2", | ||
"serve-static": "^1.14.1", | ||
"signal-exit": "^3.0.5", | ||
"tmp-promise": "^3.0.2", | ||
"ws": "^8.2.0" | ||
"tmp-promise": "^3.0.3", | ||
"ws": "^8.2.3", | ||
"yargs": "^17.2.1" | ||
}, | ||
"files": [ | ||
"src", | ||
"bin", | ||
"miniflare-config-stubs", | ||
"wrangler-dist", | ||
"facade.js", | ||
"vendor" | ||
"static-asset-facade.js", | ||
"vendor", | ||
"import_meta_url.js" | ||
], | ||
@@ -77,7 +85,21 @@ "scripts": { | ||
"build": "npm run clean && npm run bundle", | ||
"start": "npm run bundle && ./bin/wrangler.js" | ||
"start": "npm run bundle && NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js", | ||
"test": "npm run build && NODE_OPTIONS=--enable-source-maps jest --silent=false" | ||
}, | ||
"engines": { | ||
"node": ">=16.0.0" | ||
}, | ||
"jest": { | ||
"transform": { | ||
"^.+\\.tsx?$": [ | ||
"esbuild-jest", | ||
{ | ||
"sourcemap": true, | ||
"loaders": { | ||
".spec.ts": "tsx" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
var __awaiter = | ||
(this && this.__awaiter) || | ||
function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { | ||
return value instanceof P | ||
? value | ||
: new P(function (resolve) { | ||
resolve(value); | ||
}); | ||
} | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
function fulfilled(value) { | ||
try { | ||
step(generator.next(value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
function rejected(value) { | ||
try { | ||
step(generator["throw"](value)); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
} | ||
function step(result) { | ||
result.done | ||
? resolve(result.value) | ||
: adopt(result.value).then(fulfilled, rejected); | ||
} | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.InternalError = exports.NotFoundError = exports.MethodNotAllowedError = exports.serveSinglePageApp = exports.mapRequestToAsset = exports.getAssetFromKV = void 0; | ||
const mime = require("mime"); | ||
exports.InternalError = | ||
exports.NotFoundError = | ||
exports.MethodNotAllowedError = | ||
exports.serveSinglePageApp = | ||
exports.mapRequestToAsset = | ||
exports.getAssetFromKV = | ||
void 0; | ||
const mime = require("wrangler-mime"); | ||
const types_1 = require("./types"); | ||
Object.defineProperty(exports, "MethodNotAllowedError", { enumerable: true, get: function () { return types_1.MethodNotAllowedError; } }); | ||
Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return types_1.NotFoundError; } }); | ||
Object.defineProperty(exports, "InternalError", { enumerable: true, get: function () { return types_1.InternalError; } }); | ||
Object.defineProperty(exports, "MethodNotAllowedError", { | ||
enumerable: true, | ||
get: function () { | ||
return types_1.MethodNotAllowedError; | ||
}, | ||
}); | ||
Object.defineProperty(exports, "NotFoundError", { | ||
enumerable: true, | ||
get: function () { | ||
return types_1.NotFoundError; | ||
}, | ||
}); | ||
Object.defineProperty(exports, "InternalError", { | ||
enumerable: true, | ||
get: function () { | ||
return types_1.InternalError; | ||
}, | ||
}); | ||
const defaultCacheControl = { | ||
browserTTL: null, | ||
edgeTTL: 2 * 60 * 60 * 24, | ||
bypassCache: false, // do not bypass Cloudflare's cache | ||
browserTTL: null, | ||
edgeTTL: 2 * 60 * 60 * 24, | ||
bypassCache: false, // do not bypass Cloudflare's cache | ||
}; | ||
function assignOptions(options) { | ||
// Assign any missing options passed in to the default | ||
// options.mapRequestToAsset is handled manually later | ||
return Object.assign({ | ||
ASSET_NAMESPACE: __STATIC_CONTENT, | ||
ASSET_MANIFEST: __STATIC_CONTENT_MANIFEST, | ||
cacheControl: defaultCacheControl, | ||
defaultMimeType: 'text/plain', | ||
defaultDocument: 'index.html', | ||
}, options); | ||
// Assign any missing options passed in to the default | ||
// options.mapRequestToAsset is handled manually later | ||
return Object.assign( | ||
{ | ||
ASSET_NAMESPACE: __STATIC_CONTENT, | ||
ASSET_MANIFEST: __STATIC_CONTENT_MANIFEST, | ||
cacheControl: defaultCacheControl, | ||
defaultMimeType: "text/plain", | ||
defaultDocument: "index.html", | ||
}, | ||
options | ||
); | ||
} | ||
@@ -42,17 +90,16 @@ /** | ||
const mapRequestToAsset = (request, options) => { | ||
options = assignOptions(options); | ||
const parsedUrl = new URL(request.url); | ||
let pathname = parsedUrl.pathname; | ||
if (pathname.endsWith('/')) { | ||
// If path looks like a directory append options.defaultDocument | ||
// e.g. If path is /about/ -> /about/index.html | ||
pathname = pathname.concat(options.defaultDocument); | ||
} | ||
else if (!mime.getType(pathname)) { | ||
// If path doesn't look like valid content | ||
// e.g. /about.me -> /about.me/index.html | ||
pathname = pathname.concat('/' + options.defaultDocument); | ||
} | ||
parsedUrl.pathname = pathname; | ||
return new Request(parsedUrl.toString(), request); | ||
options = assignOptions(options); | ||
const parsedUrl = new URL(request.url); | ||
let pathname = parsedUrl.pathname; | ||
if (pathname.endsWith("/")) { | ||
// If path looks like a directory append options.defaultDocument | ||
// e.g. If path is /about/ -> /about/index.html | ||
pathname = pathname.concat(options.defaultDocument); | ||
} else if (!mime.getType(pathname)) { | ||
// If path doesn't look like valid content | ||
// e.g. /about.me -> /about.me/index.html | ||
pathname = pathname.concat("/" + options.defaultDocument); | ||
} | ||
parsedUrl.pathname = pathname; | ||
return new Request(parsedUrl.toString(), request); | ||
}; | ||
@@ -66,18 +113,20 @@ exports.mapRequestToAsset = mapRequestToAsset; | ||
function serveSinglePageApp(request, options) { | ||
options = assignOptions(options); | ||
// First apply the default handler, which already has logic to detect | ||
// paths that should map to HTML files. | ||
request = mapRequestToAsset(request, options); | ||
const parsedUrl = new URL(request.url); | ||
// Detect if the default handler decided to map to | ||
// a HTML file in some specific directory. | ||
if (parsedUrl.pathname.endsWith('.html')) { | ||
// If expected HTML file was missing, just return the root index.html (or options.defaultDocument) | ||
return new Request(`${parsedUrl.origin}/${options.defaultDocument}`, request); | ||
} | ||
else { | ||
// The default handler decided this is not an HTML page. It's probably | ||
// an image, CSS, or JS file. Leave it as-is. | ||
return request; | ||
} | ||
options = assignOptions(options); | ||
// First apply the default handler, which already has logic to detect | ||
// paths that should map to HTML files. | ||
request = mapRequestToAsset(request, options); | ||
const parsedUrl = new URL(request.url); | ||
// Detect if the default handler decided to map to | ||
// a HTML file in some specific directory. | ||
if (parsedUrl.pathname.endsWith(".html")) { | ||
// If expected HTML file was missing, just return the root index.html (or options.defaultDocument) | ||
return new Request( | ||
`${parsedUrl.origin}/${options.defaultDocument}`, | ||
request | ||
); | ||
} else { | ||
// The default handler decided this is not an HTML page. It's probably | ||
// an image, CSS, or JS file. Leave it as-is. | ||
return request; | ||
} | ||
} | ||
@@ -96,13 +145,17 @@ exports.serveSinglePageApp = serveSinglePageApp; | ||
* */ | ||
const getAssetFromKV = (event, options) => __awaiter(void 0, void 0, void 0, function* () { | ||
const getAssetFromKV = (event, options) => | ||
__awaiter(void 0, void 0, void 0, function* () { | ||
options = assignOptions(options); | ||
const request = event.request; | ||
const ASSET_NAMESPACE = options.ASSET_NAMESPACE; | ||
const ASSET_MANIFEST = typeof options.ASSET_MANIFEST === 'string' | ||
const ASSET_MANIFEST = | ||
typeof options.ASSET_MANIFEST === "string" | ||
? JSON.parse(options.ASSET_MANIFEST) | ||
: options.ASSET_MANIFEST; | ||
if (typeof ASSET_NAMESPACE === 'undefined') { | ||
throw new types_1.InternalError(`there is no KV namespace bound to the script`); | ||
if (typeof ASSET_NAMESPACE === "undefined") { | ||
throw new types_1.InternalError( | ||
`there is no KV namespace bound to the script` | ||
); | ||
} | ||
const rawPathKey = new URL(request.url).pathname.replace(/^\/+/, ''); // strip any preceding /'s | ||
const rawPathKey = new URL(request.url).pathname.replace(/^\/+/, ""); // strip any preceding /'s | ||
let pathIsEncoded = false; | ||
@@ -113,45 +166,48 @@ let requestKey; | ||
if (options.mapRequestToAsset) { | ||
requestKey = options.mapRequestToAsset(request); | ||
} | ||
else if (ASSET_MANIFEST[rawPathKey]) { | ||
requestKey = request; | ||
} | ||
else if (ASSET_MANIFEST[decodeURIComponent(rawPathKey)]) { | ||
requestKey = options.mapRequestToAsset(request); | ||
} else if (ASSET_MANIFEST[rawPathKey]) { | ||
requestKey = request; | ||
} else if (ASSET_MANIFEST[decodeURIComponent(rawPathKey)]) { | ||
pathIsEncoded = true; | ||
requestKey = request; | ||
} else { | ||
const mappedRequest = mapRequestToAsset(request); | ||
const mappedRawPathKey = new URL(mappedRequest.url).pathname.replace( | ||
/^\/+/, | ||
"" | ||
); | ||
if (ASSET_MANIFEST[decodeURIComponent(mappedRawPathKey)]) { | ||
pathIsEncoded = true; | ||
requestKey = request; | ||
requestKey = mappedRequest; | ||
} else { | ||
// use default mapRequestToAsset | ||
requestKey = mapRequestToAsset(request, options); | ||
} | ||
} | ||
else { | ||
const mappedRequest = mapRequestToAsset(request); | ||
const mappedRawPathKey = new URL(mappedRequest.url).pathname.replace(/^\/+/, ''); | ||
if (ASSET_MANIFEST[decodeURIComponent(mappedRawPathKey)]) { | ||
pathIsEncoded = true; | ||
requestKey = mappedRequest; | ||
} | ||
else { | ||
// use default mapRequestToAsset | ||
requestKey = mapRequestToAsset(request, options); | ||
} | ||
} | ||
const SUPPORTED_METHODS = ['GET', 'HEAD']; | ||
const SUPPORTED_METHODS = ["GET", "HEAD"]; | ||
if (!SUPPORTED_METHODS.includes(requestKey.method)) { | ||
throw new types_1.MethodNotAllowedError(`${requestKey.method} is not a valid request method`); | ||
throw new types_1.MethodNotAllowedError( | ||
`${requestKey.method} is not a valid request method` | ||
); | ||
} | ||
const parsedUrl = new URL(requestKey.url); | ||
const pathname = pathIsEncoded ? decodeURIComponent(parsedUrl.pathname) : parsedUrl.pathname; // decode percentage encoded path only when necessary | ||
const pathname = pathIsEncoded | ||
? decodeURIComponent(parsedUrl.pathname) | ||
: parsedUrl.pathname; // decode percentage encoded path only when necessary | ||
// pathKey is the file path to look up in the manifest | ||
let pathKey = pathname.replace(/^\/+/, ''); // remove prepended / | ||
let pathKey = pathname.replace(/^\/+/, ""); // remove prepended / | ||
// @ts-ignore | ||
const cache = caches.default; | ||
let mimeType = mime.getType(pathKey) || options.defaultMimeType; | ||
if (mimeType.startsWith('text') || mimeType === 'application/javascript') { | ||
mimeType += '; charset=utf-8'; | ||
if (mimeType.startsWith("text") || mimeType === "application/javascript") { | ||
mimeType += "; charset=utf-8"; | ||
} | ||
let shouldEdgeCache = false; // false if storing in KV by raw file path i.e. no hash | ||
// check manifest for map from file path to hash | ||
if (typeof ASSET_MANIFEST !== 'undefined') { | ||
if (ASSET_MANIFEST[pathKey]) { | ||
pathKey = ASSET_MANIFEST[pathKey]; | ||
// if path key is in asset manifest, we can assume it contains a content hash and can be cached | ||
shouldEdgeCache = true; | ||
} | ||
if (typeof ASSET_MANIFEST !== "undefined") { | ||
if (ASSET_MANIFEST[pathKey]) { | ||
pathKey = ASSET_MANIFEST[pathKey]; | ||
// if path key is in asset manifest, we can assume it contains a content hash and can be cached | ||
shouldEdgeCache = true; | ||
} | ||
} | ||
@@ -164,10 +220,10 @@ // TODO this excludes search params from cache, investigate ideal behavior | ||
const evalCacheOpts = (() => { | ||
switch (typeof options.cacheControl) { | ||
case 'function': | ||
return options.cacheControl(request); | ||
case 'object': | ||
return options.cacheControl; | ||
default: | ||
return defaultCacheControl; | ||
} | ||
switch (typeof options.cacheControl) { | ||
case "function": | ||
return options.cacheControl(request); | ||
case "object": | ||
return options.cacheControl; | ||
default: | ||
return defaultCacheControl; | ||
} | ||
})(); | ||
@@ -178,113 +234,127 @@ // formats the etag depending on the response context. if the entityId | ||
// header is "null". Could be modified in future to base64 encode etc | ||
const formatETag = (entityId = pathKey, validatorType = 'strong') => { | ||
if (!entityId) { | ||
return ''; | ||
} | ||
switch (validatorType) { | ||
case 'weak': | ||
if (!entityId.startsWith('W/')) { | ||
return `W/${entityId}`; | ||
} | ||
return entityId; | ||
case 'strong': | ||
if (entityId.startsWith(`W/"`)) { | ||
entityId = entityId.replace('W/', ''); | ||
} | ||
if (!entityId.endsWith(`"`)) { | ||
entityId = `"${entityId}"`; | ||
} | ||
return entityId; | ||
default: | ||
return ''; | ||
} | ||
const formatETag = (entityId = pathKey, validatorType = "strong") => { | ||
if (!entityId) { | ||
return ""; | ||
} | ||
switch (validatorType) { | ||
case "weak": | ||
if (!entityId.startsWith("W/")) { | ||
return `W/${entityId}`; | ||
} | ||
return entityId; | ||
case "strong": | ||
if (entityId.startsWith(`W/"`)) { | ||
entityId = entityId.replace("W/", ""); | ||
} | ||
if (!entityId.endsWith(`"`)) { | ||
entityId = `"${entityId}"`; | ||
} | ||
return entityId; | ||
default: | ||
return ""; | ||
} | ||
}; | ||
options.cacheControl = Object.assign({}, defaultCacheControl, evalCacheOpts); | ||
options.cacheControl = Object.assign( | ||
{}, | ||
defaultCacheControl, | ||
evalCacheOpts | ||
); | ||
// override shouldEdgeCache if options say to bypassCache | ||
if (options.cacheControl.bypassCache || | ||
options.cacheControl.edgeTTL === null || | ||
request.method == 'HEAD') { | ||
shouldEdgeCache = false; | ||
if ( | ||
options.cacheControl.bypassCache || | ||
options.cacheControl.edgeTTL === null || | ||
request.method == "HEAD" | ||
) { | ||
shouldEdgeCache = false; | ||
} | ||
// only set max-age if explicitly passed in a number as an arg | ||
const shouldSetBrowserCache = typeof options.cacheControl.browserTTL === 'number'; | ||
const shouldSetBrowserCache = | ||
typeof options.cacheControl.browserTTL === "number"; | ||
let response = null; | ||
if (shouldEdgeCache) { | ||
response = yield cache.match(cacheKey); | ||
response = yield cache.match(cacheKey); | ||
} | ||
if (response) { | ||
if (response.status > 300 && response.status < 400) { | ||
if (response.body && 'cancel' in Object.getPrototypeOf(response.body)) { | ||
response.body.cancel(); | ||
console.log('Body exists and environment supports readable streams. Body cancelled'); | ||
} | ||
else { | ||
console.log('Environment doesnt support readable streams'); | ||
} | ||
response = new Response(null, response); | ||
if (response.status > 300 && response.status < 400) { | ||
if (response.body && "cancel" in Object.getPrototypeOf(response.body)) { | ||
response.body.cancel(); | ||
console.log( | ||
"Body exists and environment supports readable streams. Body cancelled" | ||
); | ||
} else { | ||
console.log("Environment doesnt support readable streams"); | ||
} | ||
else { | ||
// fixes #165 | ||
let opts = { | ||
headers: new Headers(response.headers), | ||
status: 0, | ||
statusText: '', | ||
}; | ||
opts.headers.set('cf-cache-status', 'HIT'); | ||
if (response.status) { | ||
opts.status = response.status; | ||
opts.statusText = response.statusText; | ||
} | ||
else if (opts.headers.has('Content-Range')) { | ||
opts.status = 206; | ||
opts.statusText = 'Partial Content'; | ||
} | ||
else { | ||
opts.status = 200; | ||
opts.statusText = 'OK'; | ||
} | ||
response = new Response(response.body, opts); | ||
response = new Response(null, response); | ||
} else { | ||
// fixes #165 | ||
let opts = { | ||
headers: new Headers(response.headers), | ||
status: 0, | ||
statusText: "", | ||
}; | ||
opts.headers.set("cf-cache-status", "HIT"); | ||
if (response.status) { | ||
opts.status = response.status; | ||
opts.statusText = response.statusText; | ||
} else if (opts.headers.has("Content-Range")) { | ||
opts.status = 206; | ||
opts.statusText = "Partial Content"; | ||
} else { | ||
opts.status = 200; | ||
opts.statusText = "OK"; | ||
} | ||
} | ||
else { | ||
const body = yield ASSET_NAMESPACE.get(pathKey, 'arrayBuffer'); | ||
if (body === null) { | ||
throw new types_1.NotFoundError(`could not find ${pathKey} in your content namespace`); | ||
response = new Response(response.body, opts); | ||
} | ||
} else { | ||
const body = yield ASSET_NAMESPACE.get(pathKey, "arrayBuffer"); | ||
if (body === null) { | ||
throw new types_1.NotFoundError( | ||
`could not find ${pathKey} in your content namespace` | ||
); | ||
} | ||
response = new Response(body); | ||
if (shouldEdgeCache) { | ||
response.headers.set("Accept-Ranges", "bytes"); | ||
response.headers.set("Content-Length", body.length); | ||
// set etag before cache insertion | ||
if (!response.headers.has("etag")) { | ||
response.headers.set("etag", formatETag(pathKey, "strong")); | ||
} | ||
response = new Response(body); | ||
if (shouldEdgeCache) { | ||
response.headers.set('Accept-Ranges', 'bytes'); | ||
response.headers.set('Content-Length', body.length); | ||
// set etag before cache insertion | ||
if (!response.headers.has('etag')) { | ||
response.headers.set('etag', formatETag(pathKey, 'strong')); | ||
} | ||
// determine Cloudflare cache behavior | ||
response.headers.set('Cache-Control', `max-age=${options.cacheControl.edgeTTL}`); | ||
event.waitUntil(cache.put(cacheKey, response.clone())); | ||
response.headers.set('CF-Cache-Status', 'MISS'); | ||
} | ||
// determine Cloudflare cache behavior | ||
response.headers.set( | ||
"Cache-Control", | ||
`max-age=${options.cacheControl.edgeTTL}` | ||
); | ||
event.waitUntil(cache.put(cacheKey, response.clone())); | ||
response.headers.set("CF-Cache-Status", "MISS"); | ||
} | ||
} | ||
response.headers.set('Content-Type', mimeType); | ||
response.headers.set("Content-Type", mimeType); | ||
if (response.status === 304) { | ||
let etag = formatETag(response.headers.get('etag'), 'strong'); | ||
let ifNoneMatch = cacheKey.headers.get('if-none-match'); | ||
let proxyCacheStatus = response.headers.get('CF-Cache-Status'); | ||
if (etag) { | ||
if (ifNoneMatch && ifNoneMatch === etag && proxyCacheStatus === 'MISS') { | ||
response.headers.set('CF-Cache-Status', 'EXPIRED'); | ||
} | ||
else { | ||
response.headers.set('CF-Cache-Status', 'REVALIDATED'); | ||
} | ||
response.headers.set('etag', formatETag(etag, 'weak')); | ||
let etag = formatETag(response.headers.get("etag"), "strong"); | ||
let ifNoneMatch = cacheKey.headers.get("if-none-match"); | ||
let proxyCacheStatus = response.headers.get("CF-Cache-Status"); | ||
if (etag) { | ||
if ( | ||
ifNoneMatch && | ||
ifNoneMatch === etag && | ||
proxyCacheStatus === "MISS" | ||
) { | ||
response.headers.set("CF-Cache-Status", "EXPIRED"); | ||
} else { | ||
response.headers.set("CF-Cache-Status", "REVALIDATED"); | ||
} | ||
response.headers.set("etag", formatETag(etag, "weak")); | ||
} | ||
} | ||
if (shouldSetBrowserCache) { | ||
response.headers.set('Cache-Control', `max-age=${options.cacheControl.browserTTL}`); | ||
response.headers.set( | ||
"Cache-Control", | ||
`max-age=${options.cacheControl.browserTTL}` | ||
); | ||
} else { | ||
response.headers.delete("Cache-Control"); | ||
} | ||
else { | ||
response.headers.delete('Cache-Control'); | ||
} | ||
return response; | ||
}); | ||
}); | ||
exports.getAssetFromKV = getAssetFromKV; |
@@ -40,3 +40,3 @@ { | ||
"dependencies": { | ||
"mime": "^2.5.2" | ||
"wrangler-mime": "^2.5.2" | ||
}, | ||
@@ -43,0 +43,0 @@ "devDependencies": { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
10494713
61
112607
25
+ Addedsemiver@^1.1.0
+ Added@miniflare/cache@2.0.0-rc.1(transitive)
+ Added@miniflare/cli-parser@2.0.0-rc.1(transitive)
+ Added@miniflare/core@2.0.0-rc.1(transitive)
+ Added@miniflare/durable-objects@2.0.0-rc.1(transitive)
+ Added@miniflare/html-rewriter@2.0.0-rc.1(transitive)
+ Added@miniflare/http-server@2.0.0-rc.1(transitive)
+ Added@miniflare/kv@2.0.0-rc.1(transitive)
+ Added@miniflare/runner-vm@2.0.0-rc.1(transitive)
+ Added@miniflare/scheduler@2.0.0-rc.1(transitive)
+ Added@miniflare/shared@2.0.0-rc.1(transitive)
+ Added@miniflare/sites@2.0.0-rc.1(transitive)
+ Added@miniflare/storage-file@2.0.0-rc.1(transitive)
+ Added@miniflare/storage-memory@2.0.0-rc.1(transitive)
+ Added@miniflare/watcher@2.0.0-rc.1(transitive)
+ Added@miniflare/web-sockets@2.0.0-rc.1(transitive)
+ Addedcron-schedule@3.0.6(transitive)
+ Addeddotenv@10.0.0(transitive)
+ Addedesbuild@0.13.12(transitive)
+ Addedesbuild-android-arm64@0.13.12(transitive)
+ Addedesbuild-darwin-64@0.13.12(transitive)
+ Addedesbuild-darwin-arm64@0.13.12(transitive)
+ Addedesbuild-freebsd-64@0.13.12(transitive)
+ Addedesbuild-freebsd-arm64@0.13.12(transitive)
+ Addedesbuild-linux-32@0.13.12(transitive)
+ Addedesbuild-linux-64@0.13.12(transitive)
+ Addedesbuild-linux-arm@0.13.12(transitive)
+ Addedesbuild-linux-arm64@0.13.12(transitive)
+ Addedesbuild-linux-mips64le@0.13.12(transitive)
+ Addedesbuild-linux-ppc64le@0.13.12(transitive)
+ Addedesbuild-netbsd-64@0.13.12(transitive)
+ Addedesbuild-openbsd-64@0.13.12(transitive)
+ Addedesbuild-sunos-64@0.13.12(transitive)
+ Addedesbuild-windows-32@0.13.12(transitive)
+ Addedesbuild-windows-64@0.13.12(transitive)
+ Addedesbuild-windows-arm64@0.13.12(transitive)
+ Addedignore@5.3.2(transitive)
+ Addedminiflare@2.0.0-rc.1(transitive)
+ Addedset-cookie-parser@2.7.1(transitive)
+ Addedundici@4.16.0(transitive)
+ Addedws@8.18.0(transitive)
- Removedyargs@^17.1.1
- Removed@cloudflare/workers-types@2.2.2(transitive)
- Removed@mrbbot/node-fetch@4.6.0(transitive)
- Removed@nodelib/fs.scandir@2.1.5(transitive)
- Removed@nodelib/fs.stat@2.0.5(transitive)
- Removed@nodelib/fs.walk@1.2.8(transitive)
- Removed@peculiar/asn1-schema@2.3.13(transitive)
- Removed@peculiar/json-schema@1.1.12(transitive)
- Removed@peculiar/webcrypto@1.5.0(transitive)
- Removed@types/node@16.18.122(transitive)
- Removed@wessberg/stringutil@1.0.19(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedansi-styles@4.3.0(transitive)
- Removedanymatch@3.1.3(transitive)
- Removedasn1js@3.0.5(transitive)
- Removedbase64-arraybuffer-es6@0.7.0(transitive)
- Removedbinary-extensions@2.3.0(transitive)
- Removedbraces@3.0.3(transitive)
- Removedchalk@4.1.2(transitive)
- Removedchokidar@3.6.0(transitive)
- Removedcjstoesm@1.1.5(transitive)
- Removedcliui@7.0.48.0.1(transitive)
- Removedcluster-key-slot@1.1.2(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedcommander@9.5.0(transitive)
- Removedcompatfactory@0.0.13(transitive)
- Removedcrosspath@1.0.0(transitive)
- Removeddebug@4.4.0(transitive)
- Removeddenque@1.5.1(transitive)
- Removeddotenv@8.6.0(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedenv-paths@2.2.1(transitive)
- Removedesbuild@0.12.29(transitive)
- Removedescalade@3.2.0(transitive)
- Removedevent-target-shim@6.0.2(transitive)
- Removedfast-glob@3.3.2(transitive)
- Removedfastq@1.17.1(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedformdata-node@2.5.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-caller-file@2.0.5(transitive)
- Removedglob-parent@5.1.2(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhelpertypes@0.0.18(transitive)
- Removedioredis@4.28.5(transitive)
- Removedis-binary-path@2.1.0(transitive)
- Removedis-core-module@2.16.1(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedis-glob@4.0.3(transitive)
- Removedis-number@7.0.0(transitive)
- Removedlodash@4.17.21(transitive)
- Removedlodash.defaults@4.2.0(transitive)
- Removedlodash.flatten@4.4.0(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedmerge2@1.4.1(transitive)
- Removedmicromatch@4.0.8(transitive)
- Removedmime-db@1.46.0(transitive)
- Removedmime-types@2.1.29(transitive)
- Removedminiflare@1.4.1(transitive)
- Removedms@2.1.3(transitive)
- Removednode-cron@2.0.3(transitive)
- Removednormalize-path@3.0.0(transitive)
- Removedopencollective-postinstall@2.0.3(transitive)
- Removedp-map@2.1.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpicomatch@2.3.1(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedpvtsutils@1.3.6(transitive)
- Removedpvutils@1.1.3(transitive)
- Removedqueue-microtask@1.2.3(transitive)
- Removedreaddirp@3.6.0(transitive)
- Removedredis-commands@1.7.0(transitive)
- Removedredis-errors@1.2.0(transitive)
- Removedredis-parser@3.0.0(transitive)
- Removedrequire-directory@2.1.1(transitive)
- Removedreserved-words@0.1.2(transitive)
- Removedresolve@1.22.10(transitive)
- Removedreusify@1.0.4(transitive)
- Removedrun-parallel@1.2.0(transitive)
- Removedsanitize-filename@1.6.3(transitive)
- Removedstandard-as-callback@2.1.0(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedsupports-color@7.2.0(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedto-regex-range@5.0.1(transitive)
- Removedtr46@2.1.0(transitive)
- Removedtruncate-utf8-bytes@1.0.2(transitive)
- Removedtslib@2.8.1(transitive)
- Removedtypescript@4.9.5(transitive)
- Removedtypeson@6.1.0(transitive)
- Removedtypeson-registry@1.0.0-alpha.39(transitive)
- Removedtz-offset@0.0.1(transitive)
- Removedutf8-byte-length@1.0.5(transitive)
- Removedweb-streams-polyfill@3.3.3(transitive)
- Removedwebcrypto-core@1.8.1(transitive)
- Removedwebidl-conversions@6.1.0(transitive)
- Removedwhatwg-url@8.7.0(transitive)
- Removedwrap-ansi@7.0.0(transitive)
- Removedws@7.5.10(transitive)
- Removedy18n@5.0.8(transitive)
- Removedyargs@16.2.017.7.2(transitive)
- Removedyargs-parser@20.2.921.1.1(transitive)
Updatedesbuild@0.13.12
Updatedminiflare@2.0.0-rc.1