forked from jason5ng32/MyIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
30 lines (24 loc) · 944 Bytes
/
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
require('dotenv').config();
const express = require('express');
const path = require('path');
const mapHandler = require('./api/map');
const validateMapKeyHandler = require('./api/validate-map-key');
const validateSite = require('./api/validate-site');
const ipinfoHandler = require('./api/ipinfo');
const ipapicomHandler = require('./api/ipapicom');
const app = express();
const port = process.env.PORT || 8966;
// 使用查询参数处理所有地图请求
app.get('/api/map', mapHandler);
// 使用查询参数处理所有 IP 地址请求
app.get('/api/ipinfo', ipinfoHandler);
app.get('/api/ipapicom', ipapicomHandler);
// 设置静态文件服务
app.use(express.static(path.join(__dirname, 'public')));
// 一些判断
app.all('/api/validate-map-key', validateMapKeyHandler);
app.all('/api/validate-site', validateSite);
// 启动服务器
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});