1
mirror of https://github.com/jakejarvis/simpip.git synced 2025-04-26 04:35:22 -04:00
simpip/index.js

32 lines
844 B
JavaScript

const handle = async (request) => {
const opts = {
headers: {
"Content-Type": "text/plain; charset=utf-8",
"Cache-Control": "no-cache, no-store, must-revalidate",
"Content-Security-Policy": "default-src 'none';",
"X-Did-You-Know": "You can use \"curl -4\" or \"curl -6\" to get either IP address!",
"X-View-Source": "https://jrvs.io/simpip",
},
};
if (new URL(request.url).pathname === "/") {
const ip = request.headers.get("cf-connecting-ip") || request.headers.get("x-forwarded-for");
return new Response(ip + "\n", {
status: 200,
statusText: "OK",
...opts,
});
}
return new Response("404 Not Found\n", {
status: 404,
statusText: "Not Found",
...opts,
});
};
addEventListener("fetch", (event) => {
event.respondWith(handle(event.request));
});