forked from jason5ng32/MyIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (40 loc) · 1.6 KB
/
server.js
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
import dotenv from 'dotenv';
import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
import mapHandler from './api/map.js';
import validateMapKeyHandler from './api/validate-map-key.js';
import validateSite from './api/validate-site.js';
import ipinfoHandler from './api/ipinfo.js';
import ipapicomHandler from './api/ipapicom.js';
import keycdnHandler from './api/keycdn.js';
import ipCheckingHandler from './api/ipchecking.js';
import ipsbHandler from './api/ipsb.js';
import cfHander from './api/cfradar.js';
import recaptchaHandler from './api/recaptcha.js';
import validateRecaptchaKey from './api/validate-recaptcha-key.js';
dotenv.config();
const app = express();
const port = process.env.PORT || 11966;
// 使用查询参数处理所有地图请求
app.get('/api/map', mapHandler);
// 使用查询参数处理所有 IP 地址请求
app.get('/api/ipinfo', ipinfoHandler);
app.get('/api/ipapicom', ipapicomHandler);
app.get('/api/keycdn', keycdnHandler);
app.get('/api/ipchecking', ipCheckingHandler);
app.get('/api/ipsb', ipsbHandler);
app.get('/api/cfradar', cfHander);
app.get('/api/recaptcha', recaptchaHandler);
// 设置静态文件服务
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
app.use(express.static(path.join(__dirname, './dist')));
// 一些判断
app.all('/api/validate-map-key', validateMapKeyHandler);
app.all('/api/validate-site', validateSite);
app.all('/api/validate-recaptcha-key', validateRecaptchaKey);
// 启动服务器
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});