Public
Back
Version 6
10/6/2024
export default async function(req: Request): Promise<Response> {
const url = new URL(req.url);
const path = url.pathname.slice(1); // Remove leading slash
const parsedStatus = parseInt(path, 10);
// Check if the parsed status is a valid HTTP status code
if (!isNaN(parsedStatus) && parsedStatus >= 100 && parsedStatus < 600) {
return new Response(null, { status: parsedStatus });
} else {
// ASCII art for "bad request"
const badRequestArt = `
_ _ _
| |__ __ _ __| | _ __ ___ __ _ _ _ ___ ___| |_
| '_ \\ / _\` |/ _\` | | '__/ _ \\/ _\` | | | |/ _ \\/ __| __|
| |_) | (_| | (_| | | | | __/ (_| | |_| | __/\\__ \\ |_
|_.__/ \\__,_|\\__,_| |_| \\___|\\__, |\\__,_|\\___|___/\\__|
|_|
`;
return new Response(badRequestArt, {
status: 400,
headers: { "Content-Type": "text/plain" },
});
}
}
rozek-gdi_statuscodeservice.web.val.run
Updated: October 6, 2024