From 5f61f6ca1334f819ebd2336af99023cb112ab31e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A0=81=E7=8C=BF?= Date: Tue, 9 Sep 2025 11:51:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 48bb675..36af2db 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,10 @@ const { execSync } = require('child_process'); const ip = require('./utils/ip'); const { port, command } = require('./config'); - const express = require('express') const app = express() const { join } = require('path'); -// 配置静态文件目录 -// 这会将项目中的public文件夹设置为静态资源目录 app.use(express.static(join(__dirname, 'public'))); app.use((req, res, next) => { @@ -17,11 +14,13 @@ app.use((req, res, next) => { next(); }); +// 提供接口,查询ubuntu server上的ipv6地址,处理字符串后,序列化为json返回 app.get('/ip', async (req, res) => { let output = execSync(command, { encoding: "utf8" }); res.json(await ip.parseNetworkInfo(output)) }) +// 静态页面,调用 /ip 接口,做页面展示 app.get('/', async (req, res) => { res.sendFile(join(__dirname, 'public', 'index.html')); })