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:
parent
5b4caff368
commit
e6d9d4f2c5
10
.github/dependabot.yml
vendored
10
.github/dependabot.yml
vendored
@ -1,10 +0,0 @@
|
||||
version: 2
|
||||
|
||||
updates:
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
versioning-strategy: increase
|
||||
schedule:
|
||||
interval: "daily"
|
||||
commit-message:
|
||||
prefix: "📦 npm:"
|
@ -1,6 +1,6 @@
|
||||
# 🌎 [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]
|
||||
|
||||
[](https://github.com/jakejarvis/simpip/actions/workflows/deploy.yml)
|
||||
|
||||
@ -41,3 +41,5 @@ jake@macbook:~$ ip
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
[playground]: https://workers.cloudflare.com/playground#LYVwNgLglgDghgJwgegGYHsHALQBM4RwDcABAEbogB2+CAngLzbPYDqApmQNJQQBimYACFKNRHSEBjAFYBGAJqyAWgA0AigFYAktIBqXAExgAXCxYduvAVhHVaEmQuXrtew2ACwAKADC6KhDsAdgAIlAAzjDo4bxQ-sYkGFh4BMQkVHDA7AwARFA07AAeAHTS4TmkqFBgQZnZeQUlZTnefgFBENgAKnQw7AlwMDBgUJIEcVTI0nAAbnDhkgiwEADUwOi44Oze3kVRSCS47Khw4BAkAN5eJCTzdFSSiewQkgAWABQI7ACOIOzhEAAlJdrjcSJJ-ACSOgYBBwiQGCCwWDXuw4EcEOEEldkcicm1AsEen0cgkcoFCihhnB8jkADSg3EkfFwN7sbAEhDoMCk5lUdDYMZsunpAUAzDsEWgAHYL5zEb4QL0xm4nIAUUKMCgX3KZIADMqmTccgAFBBwADmwDgvJy-MFrNRhqN+P8hM6AGV2JIQEsIHRsCbuaM6LajiczthwghHgByflUdix51MnIqUJQXDYeSUbBcfkAd1tOZA4LgVBIIHC7BIAB0cj6EGASNgACz16EIOsN33N7AANg7EHQJAtzxI7F4qK7WhNt1wuB14QAhCnVendFB2AXsB7KDH2LbXhAIDAschkBapyAyMUIcApnAANbsaYIGYRZAxYBamBrm4AL4MsiAFEF4KpQKgJDvImBYkAAqgASgAMp8Px-ACxS9oCxTwBArwZFkCIMIiOTIDkwI4riEJUFCsAIiQXy-P8EDFKi6LsJixRjhA7wNqggr+ImkjQFQFrYLAFEkAAPtJjHoSxbFohi4Tcc8fGFNgSQFogRxZkkFFgSqNxfBAvoVrBJCIf8US0ew7z0SszK1lQ9JIkaAIEFWCQGHqerAR5hBmeEXRFBAZIAPJcP+YLFHFMJwgFIGAmBIHgcipnmek25WTZkL2TkrZ6q2JAAHLoOcAh2C5blUcinnBQkRWtklYINVWoWUmS5WVaIuAxXFxQJeErUASloJAV4oFeN4ZjMBYPD8IIthiPQUhyIoqiaDo+hGK0bodBmkTRLE8SJIIKSEKQhH1FkhCKjalTVLUWS5GQYDoGQLS+AdRK9P0txDCMYzQP4UzhP4OxeBcOTWvkAD66ybDUpINEcTTlABs1zQtVjLX14jrU4W2uLtYDMN4QA
|
31
index.js
31
index.js
@ -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
21
package-lock.json
generated
@ -9,6 +9,8 @@
|
||||
"version": "0.0.0",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@cloudflare/workers-types": "^4.20240208.0",
|
||||
"typescript": "^5.3.3",
|
||||
"wrangler": "^3.27.0"
|
||||
}
|
||||
},
|
||||
@ -101,6 +103,12 @@
|
||||
"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": {
|
||||
"version": "0.8.1",
|
||||
"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==",
|
||||
"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": {
|
||||
"version": "5.28.3",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-5.28.3.tgz",
|
||||
|
@ -1,13 +1,15 @@
|
||||
{
|
||||
"name": "simpip",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "wrangler dev",
|
||||
"deploy": "wrangler publish"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cloudflare/workers-types": "^4.20240208.0",
|
||||
"typescript": "^5.3.3",
|
||||
"wrangler": "^3.27.0"
|
||||
}
|
||||
}
|
||||
|
31
src/index.ts
Normal file
31
src/index.ts
Normal 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
12
tsconfig.json
Normal 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"]
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
name = "simpip"
|
||||
compatibility_date = "2024-02-08"
|
||||
main = "index.js"
|
||||
main = "./src/index.ts"
|
||||
routes = [
|
||||
{ pattern = "simpip.com", custom_domain = true },
|
||||
{ pattern = "www.simpip.com", custom_domain = true }
|
||||
{ pattern = "simpip.com", custom_domain = true }
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user