hack: fake responses for .well-known stuff
This commit is contained in:
parent
9f53c9acea
commit
9b3b547fa4
|
|
@ -1,4 +1,7 @@
|
||||||
import { getAssetFromKV, mapRequestToAsset } from '@cloudflare/kv-asset-handler'
|
import {
|
||||||
|
getAssetFromKV,
|
||||||
|
mapRequestToAsset,
|
||||||
|
} from "@cloudflare/kv-asset-handler";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The DEBUG flag will do two things that help during development:
|
* The DEBUG flag will do two things that help during development:
|
||||||
|
|
@ -7,55 +10,70 @@ import { getAssetFromKV, mapRequestToAsset } from '@cloudflare/kv-asset-handler'
|
||||||
* 2. we will return an error message on exception in your Response rather
|
* 2. we will return an error message on exception in your Response rather
|
||||||
* than the default 404.html page.
|
* than the default 404.html page.
|
||||||
*/
|
*/
|
||||||
const DEBUG = false
|
const DEBUG = false;
|
||||||
|
|
||||||
addEventListener('fetch', event => {
|
|
||||||
event.respondWith(handleEvent(event))
|
|
||||||
})
|
|
||||||
|
|
||||||
|
addEventListener("fetch", (event) => {
|
||||||
|
event.respondWith(handleEvent(event));
|
||||||
|
});
|
||||||
|
/*** */
|
||||||
async function handleEvent(event) {
|
async function handleEvent(event) {
|
||||||
let options = {}
|
let options = {
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You can add custom logic to how we fetch your assets
|
* You can add custom logic to how we fetch your assets
|
||||||
* by configuring the function `mapRequestToAsset`
|
* by configuring the function `mapRequestToAsset`
|
||||||
*/
|
*/
|
||||||
// options.mapRequestToAsset = handlePrefix(/^\/docs/)
|
// options.mapRequestToAsset = handlePrefix(/^\/docs/)
|
||||||
|
console.log(event.request.url);
|
||||||
|
if (event.request.url.includes("velvox.xyz/.well-known/discord")) {
|
||||||
|
return new Response("dh=890318909273e02968da3dbc0a775799a61346c7");
|
||||||
|
} else if (event.request.url.includes("velvox.dev/.well-known/discord")) {
|
||||||
|
return new Response("dh=0886b1efe44a1f1f6460552d650b597d37174bbd");
|
||||||
|
} else if (event.request.url.includes("makecoolsh.it/.well-known/discord")) {
|
||||||
|
return new Response("dh=ef94e7778ba539f1af5bddd7960fc185dbc738fd");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
// customize caching
|
// customize caching
|
||||||
options.cacheControl = {
|
options.cacheControl = {
|
||||||
bypassCache: true,
|
bypassCache: true,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const page = await getAssetFromKV(event, options)
|
const page = await getAssetFromKV(event, options);
|
||||||
|
|
||||||
// allow headers to be altered
|
// allow headers to be altered
|
||||||
const response = new Response(page.body, page)
|
const response = new Response(page.body, page);
|
||||||
|
|
||||||
response.headers.set('X-XSS-Protection', '1; mode=block')
|
|
||||||
response.headers.set('X-Content-Type-Options', 'nosniff')
|
|
||||||
response.headers.set('X-Frame-Options', 'DENY')
|
|
||||||
response.headers.set('Referrer-Policy', 'unsafe-url')
|
|
||||||
response.headers.set('Feature-Policy', 'none')
|
|
||||||
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
response.headers.set("X-XSS-Protection", "1; mode=block");
|
||||||
|
response.headers.set("X-Content-Type-Options", "nosniff");
|
||||||
|
response.headers.set("X-Frame-Options", "DENY");
|
||||||
|
response.headers.set("Referrer-Policy", "unsafe-url");
|
||||||
|
response.headers.set("Feature-Policy", "none");
|
||||||
|
response.headers.set("x-feature", "the-game");
|
||||||
|
response.headers.set("hosting", "the-game");
|
||||||
|
response.headers.set("the", "game");
|
||||||
|
response.headers.set("x-mom-get-the-camera", "hi-people-of-otto-cord");
|
||||||
|
return response;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// if an error is thrown try to serve the asset at 404.html
|
// if an error is thrown try to serve the asset at 404.html
|
||||||
if (!DEBUG) {
|
if (!DEBUG) {
|
||||||
try {
|
try {
|
||||||
let notFoundResponse = await getAssetFromKV(event, {
|
let notFoundResponse = await getAssetFromKV(event, {
|
||||||
mapRequestToAsset: req => new Request(`${new URL(req.url).origin}/404.html`, req),
|
mapRequestToAsset: (req) =>
|
||||||
})
|
new Request(`${new URL(req.url).origin}/404.html`, req),
|
||||||
|
});
|
||||||
|
|
||||||
return new Response(notFoundResponse.body, { ...notFoundResponse, status: 404 })
|
return new Response(notFoundResponse.body, {
|
||||||
|
...notFoundResponse,
|
||||||
|
status: 404,
|
||||||
|
});
|
||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Response(e.message || e.toString(), { status: 500 })
|
return new Response(e.message || e.toString(), { status: 500 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,15 +85,15 @@ async function handleEvent(event) {
|
||||||
* to exist at a specific path.
|
* to exist at a specific path.
|
||||||
*/
|
*/
|
||||||
function handlePrefix(prefix) {
|
function handlePrefix(prefix) {
|
||||||
return request => {
|
return (request) => {
|
||||||
// compute the default (e.g. / -> index.html)
|
// compute the default (e.g. / -> index.html)
|
||||||
let defaultAssetKey = mapRequestToAsset(request)
|
let defaultAssetKey = mapRequestToAsset(request);
|
||||||
let url = new URL(defaultAssetKey.url)
|
let url = new URL(defaultAssetKey.url);
|
||||||
|
|
||||||
// strip the prefix from the path for lookup
|
// strip the prefix from the path for lookup
|
||||||
url.pathname = url.pathname.replace(prefix, '/')
|
url.pathname = url.pathname.replace(prefix, "/");
|
||||||
|
|
||||||
// inherit all other props from the default request
|
// inherit all other props from the default request
|
||||||
return new Request(url.toString(), defaultAssetKey)
|
return new Request(url.toString(), defaultAssetKey);
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue