LanYunのBlog

LanYunのBlog

马上订阅 LanYunのBlog RSS 更新: https://lanyundev.com/atom.xml

利用CloudFlare Workers快速自建一个IP获取器

2023年3月11日 11:23

前言

本文主要记录如何快速为自己的网站建立一个安全的ip获取器.

关于前面的一些设置Workers操作可以看这篇文章

本文主要给出代码.

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// 内容参考:https://blog.dsrkafuu.net/post/2020/cloudflare-worker-cors-anywhere/

// 允许请求的 CORS 来源及其Referer
const ALLOWED_ORIGIN = [/^https:\/\/lanyundev\.com\/$/];
// 是否不拒绝所有无 Origin 请求
const ALLOW_NO_ORIGIN = false;
// 允许请求的 Referer
const ALLOWED_Referer = [/^https:\/\/lanyundev\.com\/$/];
// 是否不拒绝所有无 Referer 请求
const ALLOW_NO_Referer = false;
// 缓存控制
const CACHE_CONTROL = 'public, max-age=2592000'; //30天缓存 // no-cache, must-revalidate

/**
* 验证 Origin
* @param {Request} req
* @return {boolean}
*/

function validateOrigin(...

剩余内容已隐藏

查看完整文章以阅读更多