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')); })