-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use newer fetch handler w/ typescript
- Loading branch information
1 parent
5b4caff
commit e6d9d4f
Showing
8 changed files
with
72 additions
and
46 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
] |