1
mirror of https://github.com/jakejarvis/simpip.git synced 2025-04-26 01:05:23 -04:00

use newer fetch handler w/ typescript

This commit is contained in:
Jake Jarvis 2024-02-20 09:38:28 -05:00
parent 5b4caff368
commit e6d9d4f2c5
Signed by: jake
SSH Key Fingerprint: SHA256:nCkvAjYA6XaSPUqc4TfbBQTpzr8Xj7ritg/sGInCdkc
8 changed files with 72 additions and 46 deletions

View File

@ -1,10 +0,0 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
versioning-strategy: increase
schedule:
interval: "daily"
commit-message:
prefix: "📦 npm:"

View File

@ -1,6 +1,6 @@
# 🌎 [simpip](https://simpip.com/) # 🌎 [simpip](https://simpip.com/)
**⚡ Now powered purely by [Cloudflare Workers](https://www.cloudflare.com/products/cloudflare-workers/), making it _blazing_ fast from anywhere in the world — and even simpler!** [Try this code on the playground.](https://cloudflareworkers.com/#ad749bc793a44b32186fc5d10fddf163:https://simpip.com/) **⚡ Now powered purely by [Cloudflare Workers](https://www.cloudflare.com/products/cloudflare-workers/), making it _blazing_ fast from anywhere in the world — and even simpler!** [Try this code on the playground.][playground]
[![Deploy Cloudflare Worker](https://github.com/jakejarvis/simpip/actions/workflows/deploy.yml/badge.svg)](https://github.com/jakejarvis/simpip/actions/workflows/deploy.yml) [![Deploy Cloudflare Worker](https://github.com/jakejarvis/simpip/actions/workflows/deploy.yml/badge.svg)](https://github.com/jakejarvis/simpip/actions/workflows/deploy.yml)
@ -41,3 +41,5 @@ jake@macbook:~$ ip
## License ## License
MIT MIT
[playground]: https://workers.cloudflare.com/playground#LYVwNgLglgDghgJwgegGYHsHALQBM4RwDcABAEbogB2+CAngLzbPYDqApmQNJQQBimYACFKNRHSEBjAFYBGAJqyAWgA0AigFYAktIBqXAExgAXCxYduvAVhHVaEmQuXrtew2ACwAKADC6KhDsAdgAIlAAzjDo4bxQ-sYkGFh4BMQkVHDA7AwARFA07AAeAHTS4TmkqFBgQZnZeQUlZTnefgFBENgAKnQw7AlwMDBgUJIEcVTI0nAAbnDhkgiwEADUwOi44Oze3kVRSCS47Khw4BAkAN5eJCTzdFSSiewQkgAWABQI7ACOIOzhEAAlJdrjcSJJ-ACSOgYBBwiQGCCwWDXuw4EcEOEEldkcicm1AsEen0cgkcoFCihhnB8jkADSg3EkfFwN7sbAEhDoMCk5lUdDYMZsunpAUAzDsEWgAHYL5zEb4QL0xm4nIAUUKMCgX3KZIADMqmTccgAFBBwADmwDgvJy-MFrNRhqN+P8hM6AGV2JIQEsIHRsCbuaM6LajiczthwghHgByflUdix51MnIqUJQXDYeSUbBcfkAd1tOZA4LgVBIIHC7BIAB0cj6EGASNgACz16EIOsN33N7AANg7EHQJAtzxI7F4qK7WhNt1wuB14QAhCnVendFB2AXsB7KDH2LbXhAIDAschkBapyAyMUIcApnAANbsaYIGYRZAxYBamBrm4AL4MsiAFEF4KpQKgJDvImBYkAAqgASgAMp8Px-ACxS9oCxTwBArwZFkCIMIiOTIDkwI4riEJUFCsAIiQXy-P8EDFKi6LsJixRjhA7wNqggr+ImkjQFQFrYLAFEkAAPtJjHoSxbFohi4Tcc8fGFNgSQFogRxZkkFFgSqNxfBAvoVrBJCIf8US0ew7z0SszK1lQ9JIkaAIEFWCQGHqerAR5hBmeEXRFBAZIAPJcP+YLFHFMJwgFIGAmBIHgcipnmek25WTZkL2TkrZ6q2JAAHLoOcAh2C5blUcinnBQkRWtklYINVWoWUmS5WVaIuAxXFxQJeErUASloJAV4oFeN4ZjMBYPD8IIthiPQUhyIoqiaDo+hGK0bodBmkTRLE8SJIIKSEKQhH1FkhCKjalTVLUWS5GQYDoGQLS+AdRK9P0txDCMYzQP4UzhP4OxeBcOTWvkAD66ybDUpINEcTTlABs1zQtVjLX14jrU4W2uLtYDMN4QA

View File

@ -1,31 +0,0 @@
const handle = async (request) => {
const opts = {
headers: {
"Content-Type": "text/plain",
"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://github.com/jakejarvis/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));
});

21
package-lock.json generated
View File

@ -9,6 +9,8 @@
"version": "0.0.0", "version": "0.0.0",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@cloudflare/workers-types": "^4.20240208.0",
"typescript": "^5.3.3",
"wrangler": "^3.27.0" "wrangler": "^3.27.0"
} }
}, },
@ -101,6 +103,12 @@
"node": ">=16" "node": ">=16"
} }
}, },
"node_modules/@cloudflare/workers-types": {
"version": "4.20240208.0",
"resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-4.20240208.0.tgz",
"integrity": "sha512-MVGTTjZpJu4kJONvai5SdJzWIhOJbuweVZ3goI7FNyG+JdoQH41OoB+nMhLsX626vPLZVWGPIWsiSo/WZHzgQw==",
"dev": true
},
"node_modules/@cspotcode/source-map-support": { "node_modules/@cspotcode/source-map-support": {
"version": "0.8.1", "version": "0.8.1",
"resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz",
@ -1146,6 +1154,19 @@
"integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==",
"dev": true "dev": true
}, },
"node_modules/typescript": {
"version": "5.3.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz",
"integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==",
"dev": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=14.17"
}
},
"node_modules/undici": { "node_modules/undici": {
"version": "5.28.3", "version": "5.28.3",
"resolved": "https://registry.npmjs.org/undici/-/undici-5.28.3.tgz", "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.3.tgz",

View File

@ -1,13 +1,15 @@
{ {
"name": "simpip", "name": "simpip",
"version": "0.0.0", "version": "0.0.0",
"private": true,
"license": "MIT", "license": "MIT",
"main": "index.js",
"scripts": { "scripts": {
"start": "wrangler dev", "start": "wrangler dev",
"deploy": "wrangler publish" "deploy": "wrangler publish"
}, },
"devDependencies": { "devDependencies": {
"@cloudflare/workers-types": "^4.20240208.0",
"typescript": "^5.3.3",
"wrangler": "^3.27.0" "wrangler": "^3.27.0"
} }
} }

31
src/index.ts Normal file
View File

@ -0,0 +1,31 @@
export default {
async fetch(request: Request) {
const opts = {
headers: {
"Content-Type": "text/plain",
"Cache-Control": "no-cache, no-store, must-revalidate",
"Expires": "0",
"Pragma": "no-cache",
"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://github.com/jakejarvis/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,
});
},
} satisfies ExportedHandler;

12
tsconfig.json Normal file
View File

@ -0,0 +1,12 @@
{
"compilerOptions": {
"noEmit": true,
"module": "esnext",
"target": "esnext",
"lib": ["esnext"],
"strict": true,
"moduleResolution": "node",
"types": ["@cloudflare/workers-types"]
},
"exclude": ["node_modules"]
}

View File

@ -1,7 +1,6 @@
name = "simpip" name = "simpip"
compatibility_date = "2024-02-08" compatibility_date = "2024-02-08"
main = "index.js" main = "./src/index.ts"
routes = [ routes = [
{ pattern = "simpip.com", custom_domain = true }, { pattern = "simpip.com", custom_domain = true }
{ pattern = "www.simpip.com", custom_domain = true }
] ]