Website Structure
This commit is contained in:
parent
62812f2090
commit
71f0676a62
22365 changed files with 4265753 additions and 791 deletions
66
Frontend-Learner/node_modules/@cloudflare/kv-asset-handler/dist/index.d.ts
generated
vendored
Normal file
66
Frontend-Learner/node_modules/@cloudflare/kv-asset-handler/dist/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
declare global {
|
||||
const __STATIC_CONTENT: KVNamespace | undefined;
|
||||
const __STATIC_CONTENT_MANIFEST: Record<string, string> | undefined;
|
||||
}
|
||||
type CacheControl = {
|
||||
browserTTL: number;
|
||||
edgeTTL: number;
|
||||
bypassCache: boolean;
|
||||
};
|
||||
type AssetManifestType = Record<string, string>;
|
||||
type Options = {
|
||||
cacheControl: ((req: Request) => Partial<CacheControl>) | Partial<CacheControl>;
|
||||
ASSET_NAMESPACE: KVNamespace;
|
||||
ASSET_MANIFEST: AssetManifestType | string;
|
||||
mapRequestToAsset?: (req: Request, options?: Partial<Options>) => Request;
|
||||
defaultMimeType: string;
|
||||
defaultDocument: string;
|
||||
pathIsEncoded: boolean;
|
||||
defaultETag: "strong" | "weak";
|
||||
};
|
||||
declare class KVError extends Error {
|
||||
constructor(message?: string, status?: number);
|
||||
status: number;
|
||||
}
|
||||
declare class MethodNotAllowedError extends KVError {
|
||||
constructor(message?: string, status?: number);
|
||||
}
|
||||
declare class NotFoundError extends KVError {
|
||||
constructor(message?: string, status?: number);
|
||||
}
|
||||
declare class InternalError extends KVError {
|
||||
constructor(message?: string, status?: number);
|
||||
}
|
||||
|
||||
/**
|
||||
* maps the path of incoming request to the request pathKey to look up
|
||||
* in bucket and in cache
|
||||
* e.g. for a path '/' returns '/index.html' which serves
|
||||
* the content of bucket/index.html
|
||||
* @param {Request} request incoming request
|
||||
*/
|
||||
declare const mapRequestToAsset: (request: Request, options?: Partial<Options>) => Request<unknown, CfProperties<unknown>>;
|
||||
/**
|
||||
* maps the path of incoming request to /index.html if it evaluates to
|
||||
* any HTML file.
|
||||
* @param {Request} request incoming request
|
||||
*/
|
||||
declare function serveSinglePageApp(request: Request, options?: Partial<Options>): Request;
|
||||
/**
|
||||
* takes the path of the incoming request, gathers the appropriate content from KV, and returns
|
||||
* the response
|
||||
*
|
||||
* @param {FetchEvent} event the fetch event of the triggered request
|
||||
* @param {{mapRequestToAsset: (string: Request) => Request, cacheControl: {bypassCache:boolean, edgeTTL: number, browserTTL:number}, ASSET_NAMESPACE: any, ASSET_MANIFEST:any}} [options] configurable options
|
||||
* @param {CacheControl} [options.cacheControl] determine how to cache on Cloudflare and the browser
|
||||
* @param {typeof(options.mapRequestToAsset)} [options.mapRequestToAsset] maps the path of incoming request to the request pathKey to look up
|
||||
* @param {Object | string} [options.ASSET_NAMESPACE] the binding to the namespace that script references
|
||||
* @param {any} [options.ASSET_MANIFEST] the map of the key to cache and store in KV
|
||||
* */
|
||||
type Evt = {
|
||||
request: Request;
|
||||
waitUntil: (promise: Promise<unknown>) => void;
|
||||
};
|
||||
declare const getAssetFromKV: (event: Evt, options?: Partial<Options>) => Promise<Response>;
|
||||
|
||||
export { type CacheControl, InternalError, MethodNotAllowedError, NotFoundError, type Options, getAssetFromKV, mapRequestToAsset, serveSinglePageApp };
|
||||
268
Frontend-Learner/node_modules/@cloudflare/kv-asset-handler/dist/index.js
generated
vendored
Normal file
268
Frontend-Learner/node_modules/@cloudflare/kv-asset-handler/dist/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,268 @@
|
|||
import * as mime from 'mime';
|
||||
|
||||
var __defProp = Object.defineProperty;
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
|
||||
// src/types.ts
|
||||
var KVError = class _KVError extends Error {
|
||||
static {
|
||||
__name(this, "KVError");
|
||||
}
|
||||
constructor(message, status = 500) {
|
||||
super(message);
|
||||
Object.setPrototypeOf(this, new.target.prototype);
|
||||
this.name = _KVError.name;
|
||||
this.status = status;
|
||||
}
|
||||
status;
|
||||
};
|
||||
var MethodNotAllowedError = class extends KVError {
|
||||
static {
|
||||
__name(this, "MethodNotAllowedError");
|
||||
}
|
||||
constructor(message = `Not a valid request method`, status = 405) {
|
||||
super(message, status);
|
||||
}
|
||||
};
|
||||
var NotFoundError = class extends KVError {
|
||||
static {
|
||||
__name(this, "NotFoundError");
|
||||
}
|
||||
constructor(message = `Not Found`, status = 404) {
|
||||
super(message, status);
|
||||
}
|
||||
};
|
||||
var InternalError = class extends KVError {
|
||||
static {
|
||||
__name(this, "InternalError");
|
||||
}
|
||||
constructor(message = `Internal Error in KV Asset Handler`, status = 500) {
|
||||
super(message, status);
|
||||
}
|
||||
};
|
||||
|
||||
// src/index.ts
|
||||
var defaultCacheControl = {
|
||||
browserTTL: null,
|
||||
edgeTTL: 2 * 60 * 60 * 24,
|
||||
// 2 days
|
||||
bypassCache: false
|
||||
// do not bypass Cloudflare's cache
|
||||
};
|
||||
var parseStringAsObject = /* @__PURE__ */ __name((maybeString) => typeof maybeString === "string" ? JSON.parse(maybeString) : maybeString, "parseStringAsObject");
|
||||
function getAssetFromKVDefaultOptions() {
|
||||
return {
|
||||
ASSET_NAMESPACE: typeof __STATIC_CONTENT !== "undefined" ? __STATIC_CONTENT : void 0,
|
||||
ASSET_MANIFEST: typeof __STATIC_CONTENT_MANIFEST !== "undefined" ? parseStringAsObject(__STATIC_CONTENT_MANIFEST) : {},
|
||||
cacheControl: defaultCacheControl,
|
||||
defaultMimeType: "text/plain",
|
||||
defaultDocument: "index.html",
|
||||
pathIsEncoded: false,
|
||||
defaultETag: "strong"
|
||||
};
|
||||
}
|
||||
__name(getAssetFromKVDefaultOptions, "getAssetFromKVDefaultOptions");
|
||||
function assignOptions(options) {
|
||||
return Object.assign({}, getAssetFromKVDefaultOptions(), options);
|
||||
}
|
||||
__name(assignOptions, "assignOptions");
|
||||
var mapRequestToAsset = /* @__PURE__ */ __name((request, options) => {
|
||||
options = assignOptions(options);
|
||||
const parsedUrl = new URL(request.url);
|
||||
let pathname = parsedUrl.pathname;
|
||||
if (pathname.endsWith("/")) {
|
||||
pathname = pathname.concat(options.defaultDocument);
|
||||
} else if (!mime.getType(pathname)) {
|
||||
pathname = pathname.concat("/" + options.defaultDocument);
|
||||
}
|
||||
parsedUrl.pathname = pathname;
|
||||
return new Request(parsedUrl.toString(), request);
|
||||
}, "mapRequestToAsset");
|
||||
function serveSinglePageApp(request, options) {
|
||||
options = assignOptions(options);
|
||||
request = mapRequestToAsset(request, options);
|
||||
const parsedUrl = new URL(request.url);
|
||||
if (parsedUrl.pathname.endsWith(".html")) {
|
||||
return new Request(
|
||||
`${parsedUrl.origin}/${options.defaultDocument}`,
|
||||
request
|
||||
);
|
||||
} else {
|
||||
return request;
|
||||
}
|
||||
}
|
||||
__name(serveSinglePageApp, "serveSinglePageApp");
|
||||
var getAssetFromKV = /* @__PURE__ */ __name(async (event, options) => {
|
||||
options = assignOptions(options);
|
||||
const request = event.request;
|
||||
const ASSET_NAMESPACE = options.ASSET_NAMESPACE;
|
||||
const ASSET_MANIFEST = parseStringAsObject(
|
||||
options.ASSET_MANIFEST
|
||||
);
|
||||
if (typeof ASSET_NAMESPACE === "undefined") {
|
||||
throw new InternalError(`there is no KV namespace bound to the script`);
|
||||
}
|
||||
const rawPathKey = new URL(request.url).pathname.replace(/^\/+/, "");
|
||||
let pathIsEncoded = options.pathIsEncoded;
|
||||
let requestKey;
|
||||
if (options.mapRequestToAsset) {
|
||||
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 = mappedRequest;
|
||||
} else {
|
||||
requestKey = mapRequestToAsset(request, options);
|
||||
}
|
||||
}
|
||||
const SUPPORTED_METHODS = ["GET", "HEAD"];
|
||||
if (!SUPPORTED_METHODS.includes(requestKey.method)) {
|
||||
throw new MethodNotAllowedError(
|
||||
`${requestKey.method} is not a valid request method`
|
||||
);
|
||||
}
|
||||
const parsedUrl = new URL(requestKey.url);
|
||||
const pathname = pathIsEncoded ? decodeURIComponent(parsedUrl.pathname) : parsedUrl.pathname;
|
||||
let pathKey = pathname.replace(/^\/+/, "");
|
||||
const cache = caches.default;
|
||||
let mimeType = mime.getType(pathKey) || options.defaultMimeType;
|
||||
if (mimeType.startsWith("text") || mimeType === "application/javascript") {
|
||||
mimeType += "; charset=utf-8";
|
||||
}
|
||||
let shouldEdgeCache = false;
|
||||
if (typeof ASSET_MANIFEST !== "undefined") {
|
||||
if (ASSET_MANIFEST[pathKey]) {
|
||||
pathKey = ASSET_MANIFEST[pathKey];
|
||||
shouldEdgeCache = true;
|
||||
}
|
||||
}
|
||||
const cacheKey = new Request(`${parsedUrl.origin}/${pathKey}`, request);
|
||||
const evalCacheOpts = (() => {
|
||||
switch (typeof options.cacheControl) {
|
||||
case "function":
|
||||
return options.cacheControl(request);
|
||||
case "object":
|
||||
return options.cacheControl;
|
||||
default:
|
||||
return defaultCacheControl;
|
||||
}
|
||||
})();
|
||||
const formatETag = /* @__PURE__ */ __name((entityId = pathKey, validatorType = options.defaultETag) => {
|
||||
if (!entityId) {
|
||||
return "";
|
||||
}
|
||||
switch (validatorType) {
|
||||
case "weak":
|
||||
if (!entityId.startsWith("W/")) {
|
||||
if (entityId.startsWith(`"`) && entityId.endsWith(`"`)) {
|
||||
return `W/${entityId}`;
|
||||
}
|
||||
return `W/"${entityId}"`;
|
||||
}
|
||||
return entityId;
|
||||
case "strong":
|
||||
if (entityId.startsWith(`W/"`)) {
|
||||
entityId = entityId.replace("W/", "");
|
||||
}
|
||||
if (!entityId.endsWith(`"`)) {
|
||||
entityId = `"${entityId}"`;
|
||||
}
|
||||
return entityId;
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}, "formatETag");
|
||||
options.cacheControl = Object.assign({}, defaultCacheControl, evalCacheOpts);
|
||||
if (options.cacheControl.bypassCache || options.cacheControl.edgeTTL === null || request.method == "HEAD") {
|
||||
shouldEdgeCache = false;
|
||||
}
|
||||
const shouldSetBrowserCache = typeof options.cacheControl.browserTTL === "number";
|
||||
let response = null;
|
||||
if (shouldEdgeCache) {
|
||||
response = await cache.match(cacheKey);
|
||||
}
|
||||
if (response) {
|
||||
if (response.status > 300 && response.status < 400) {
|
||||
if (response.body && "cancel" in Object.getPrototypeOf(response.body)) {
|
||||
response.body.cancel();
|
||||
}
|
||||
response = new Response(null, response);
|
||||
} else {
|
||||
const 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);
|
||||
}
|
||||
} else {
|
||||
const body = await ASSET_NAMESPACE.get(pathKey, "arrayBuffer");
|
||||
if (body === null) {
|
||||
throw new 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", String(body.byteLength));
|
||||
if (!response.headers.has("etag")) {
|
||||
response.headers.set("etag", formatETag(pathKey));
|
||||
}
|
||||
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);
|
||||
if (response.status === 304) {
|
||||
const etag = formatETag(response.headers.get("etag"));
|
||||
const ifNoneMatch = cacheKey.headers.get("if-none-match");
|
||||
const 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}`
|
||||
);
|
||||
} else {
|
||||
response.headers.delete("Cache-Control");
|
||||
}
|
||||
return response;
|
||||
}, "getAssetFromKV");
|
||||
|
||||
export { InternalError, MethodNotAllowedError, NotFoundError, getAssetFromKV, mapRequestToAsset, serveSinglePageApp };
|
||||
//# sourceMappingURL=index.js.map
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
Frontend-Learner/node_modules/@cloudflare/kv-asset-handler/dist/index.js.map
generated
vendored
Normal file
1
Frontend-Learner/node_modules/@cloudflare/kv-asset-handler/dist/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
Frontend-Learner/node_modules/@cloudflare/kv-asset-handler/dist/metafile-esm.json
generated
vendored
Normal file
1
Frontend-Learner/node_modules/@cloudflare/kv-asset-handler/dist/metafile-esm.json
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"inputs":{"src/types.ts":{"bytes":1545,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":11207,"imports":[{"path":"mime","kind":"import-statement","external":true},{"path":"src/types.ts","kind":"import-statement","original":"./types"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"dist/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":19598},"dist/index.js":{"imports":[{"path":"mime","kind":"import-statement","external":true}],"exports":["CacheControl","InternalError","MethodNotAllowedError","NotFoundError","Options","getAssetFromKV","mapRequestToAsset","serveSinglePageApp"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":7750},"src/types.ts":{"bytesInOutput":881}},"bytes":8942}}}
|
||||
Loading…
Add table
Add a link
Reference in a new issue