Skip to content

Commit

Permalink
feat: add ipinfo worker
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed May 4, 2023
1 parent 03d9adf commit 85a6e6b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/workers/ipinfo/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
root: true,
extends: ['weblint'],
rules: {
'import/no-anonymous-default-export': 'off'
}
};
1 change: 1 addition & 0 deletions packages/workers/ipinfo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# IPInfo worker
22 changes: 22 additions & 0 deletions packages/workers/ipinfo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@workers/ipinfo",
"version": "0.0.0",
"private": true,
"license": "GPL-3.0",
"scripts": {
"dev": "wrangler dev --port 8086 --local",
"worker:deploy": "wrangler publish",
"typecheck": "tsc --pretty",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --fix --ext .ts",
"prettier": "prettier --check \"**/*.{js,ts,tsx,md}\" --cache",
"prettier:fix": "prettier --write \"**/*.{js,ts,tsx,md}\" --cache"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20230419.0",
"eslint-config-weblint": "workspace:*",
"tsconfig": "workspace:*",
"typescript": "^5.0.4",
"wrangler": "^2.19.0"
}
}
17 changes: 17 additions & 0 deletions packages/workers/ipinfo/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const handleRequest = async (request: Request) => {
try {
const ip = request.headers.get('cf-connecting-ip');
const country = request.headers.get('cf-ipcountry');
const ray = request.headers.get('cf-ray');

return new Response(JSON.stringify({ success: true, ip, country, ray }));
} catch {
return new Response(JSON.stringify({ success: false }));
}
};

export default {
async fetch(request: Request) {
return await handleRequest(request);
}
};
6 changes: 6 additions & 0 deletions packages/workers/ipinfo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "tsconfig/base.json",
"compilerOptions": {
"types": ["@cloudflare/workers-types"]
}
}
7 changes: 7 additions & 0 deletions packages/workers/ipinfo/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name = "ipinfo"
main = "src/index.ts"
compatibility_date = "2023-01-25"

routes = [
{ pattern = "ipinfo.lenster.xyz", custom_domain = true }
]

0 comments on commit 85a6e6b

Please sign in to comment.