Skip to content

Commit

Permalink
use newer fetch handler w/ typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
jakejarvis committed Feb 20, 2024
1 parent 5b4caff commit e6d9d4f
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 46 deletions.
10 changes: 0 additions & 10 deletions .github/dependabot.yml

This file was deleted.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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]

[![Deploy Cloudflare Worker](https://github.com/jakejarvis/simpip/actions/workflows/deploy.yml/badge.svg)](https://github.com/jakejarvis/simpip/actions/workflows/deploy.yml)

Expand Down Expand Up @@ -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 changes: 0 additions & 31 deletions index.js

This file was deleted.

21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 changes: 31 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 12 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"noEmit": true,
"module": "esnext",
"target": "esnext",
"lib": ["esnext"],
"strict": true,
"moduleResolution": "node",
"types": ["@cloudflare/workers-types"]
},
"exclude": ["node_modules"]
}
5 changes: 2 additions & 3 deletions wrangler.toml
Original file line number Diff line number Diff line change
@@ -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 }
]

0 comments on commit e6d9d4f

Please sign in to comment.