fix ipread
This commit is contained in:
parent
68b87a9956
commit
56d28ad939
10
config.json
10
config.json
@ -1 +1,9 @@
|
|||||||
{"port":7000,"login":false,"host":"","user":"","password":"","maincidr":"","proxycidr":""}
|
{
|
||||||
|
"port": 7000,
|
||||||
|
"login": false,
|
||||||
|
"host": "",
|
||||||
|
"user": "",
|
||||||
|
"password": "",
|
||||||
|
"maincidr": "",
|
||||||
|
"proxycidr": ""
|
||||||
|
}
|
||||||
|
6
index.ts
6
index.ts
@ -4,7 +4,6 @@ import { RouterOSAPI } from 'node-routeros';
|
|||||||
const path = '/config/config.json';
|
const path = '/config/config.json';
|
||||||
const cfgfile = Bun.file(path);
|
const cfgfile = Bun.file(path);
|
||||||
let cfg = await cfgfile.json();
|
let cfg = await cfgfile.json();
|
||||||
console.log(cfg);
|
|
||||||
|
|
||||||
let api = new RouterOSAPI({
|
let api = new RouterOSAPI({
|
||||||
host: cfg.host,
|
host: cfg.host,
|
||||||
@ -33,7 +32,7 @@ if (haslogin) {
|
|||||||
|
|
||||||
const server = serve({
|
const server = serve({
|
||||||
port: cfg.port,
|
port: cfg.port,
|
||||||
async fetch(request) {
|
async fetch(request, server) {
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
if (url.pathname === '/') {
|
if (url.pathname === '/') {
|
||||||
let file = haslogin
|
let file = haslogin
|
||||||
@ -72,7 +71,8 @@ const server = serve({
|
|||||||
if (url.pathname === '/core/get/') {
|
if (url.pathname === '/core/get/') {
|
||||||
if (!haslogin)
|
if (!haslogin)
|
||||||
return new Response('ROS配置未设置', { status: 401 });
|
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)));
|
return new Response(JSON.stringify(await getDHCPList(ipaddr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user