Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,6 @@ dist
.env*
!.env.example
.wrangler/

# Deno
.deno/
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,33 @@ curl -sI https://ip.hydrz.cn

- **代码风格**:遵循 JavaScript 编码规范,使用 Biome 格式化工具。

## 运行时支持

项目同时兼容 **Node.js + Cloudflare Workers**(默认部署目标)和 **Deno** 运行时。

### Node.js / Cloudflare(默认)

```bash
pnpm install
pnpm dev # 本地开发
pnpm build # 构建到 dist/
pnpm deploy # 通过 wrangler 部署到 Cloudflare
```

### Deno

需要本地安装 [Deno](https://deno.com/) ≥ 1.45。所有依赖(vite、插件等)会通过 `npm:` 说明符自动获取,无需 `node_modules`,但首次运行会生成本地缓存。

```bash
deno task dev # 启动 Vite 开发服务器(跳过 Cloudflare 插件)
deno task build # 构建到 dist/
deno task serve # 用 Deno 原生 HTTP 服务托管 dist/,并注入 x-client-* / x-edge-* 头
deno task preview # build + serve
deno task deploy:deno # 可选:通过 deployctl 部署到 Deno Deploy
```

`server.ts` 在 Deno 端复现了 Cloudflare 边缘注入的自定义响应头(`x-client-ip`、`x-client-asn`、`x-client-geo`、`x-edge-ip`、`x-edge-colo`),因此前端代码、curl 示例和 iframe 嵌入方式都可以无修改在 Deno 下工作。地理信息会优先读取上游代理(Cloudflare/Vercel)传入的相应头,否则留空;`x-edge-colo` 在 Deno Deploy 上来自 `DENO_REGION` 环境变量。

## 贡献指南

欢迎提交 Issue 和 Pull Request!请确保:
Expand Down
28 changes: 28 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "https://raw.githubusercontent.com/denoland/deno/main/cli/schemas/config-file.v1.json",
"nodeModulesDir": "auto",
"tasks": {
"dev": "DEPLOY_TARGET=deno deno run -A npm:vite",
"build": "DEPLOY_TARGET=deno deno run -A npm:vite build",
"preview": "deno task build && deno task serve",
"serve": "deno run -A --env-file=.env server.ts",
"deploy:deno": "deno task build && deployctl deploy --project=ip --entrypoint=server.ts --include=server.ts,dist",
"lint": "deno run -A npm:@biomejs/biome check --write"
},
"imports": {
"@std/http": "jsr:@std/http@^1.0.0",
"@std/path": "jsr:@std/path@^1.0.0",
"@std/media-types": "jsr:@std/media-types@^1.0.0",
"@std/fs": "jsr:@std/fs@^1.0.0"
},
"fmt": {
"useTabs": true,
"lineWidth": 120,
"singleQuote": false,
"exclude": ["dist/", "node_modules/", "public/"]
},
"lint": {
"exclude": ["dist/", "node_modules/", "public/"]
},
"exclude": ["dist/", "node_modules/", "public/", "images/"]
}
Loading