diff --git a/config.json b/config.json index 8cdf38c..bfa2662 100644 --- a/config.json +++ b/config.json @@ -1 +1,9 @@ -{"port":7000,"login":false,"host":"","user":"","password":"","maincidr":"","proxycidr":""} \ No newline at end of file +{ + "port": 7000, + "login": false, + "host": "", + "user": "", + "password": "", + "maincidr": "", + "proxycidr": "" +} diff --git a/index.ts b/index.ts index 64e3ee9..8ec33ac 100644 --- a/index.ts +++ b/index.ts @@ -4,7 +4,6 @@ import { RouterOSAPI } from 'node-routeros'; const path = '/config/config.json'; const cfgfile = Bun.file(path); let cfg = await cfgfile.json(); -console.log(cfg); let api = new RouterOSAPI({ host: cfg.host, @@ -33,7 +32,7 @@ if (haslogin) { const server = serve({ port: cfg.port, - async fetch(request) { + async fetch(request, server) { const url = new URL(request.url); if (url.pathname === '/') { let file = haslogin @@ -72,7 +71,8 @@ const server = serve({ if (url.pathname === '/core/get/') { if (!haslogin) return new Response('ROS配置未设置', { status: 401 }); - let ipaddr = request.headers.get('x-forwarded-for'); + const sockaddr = server.requestIP(request); + let ipaddr = sockaddr === null ? '' : sockaddr.address; return new Response(JSON.stringify(await getDHCPList(ipaddr))); }