diff --git a/config/config-sample.json b/config/config-sample.json index 2253f78..b937a1b 100644 --- a/config/config-sample.json +++ b/config/config-sample.json @@ -6,7 +6,7 @@ "NBI_PORT" : 7557, "FS_INTERFACE" : "0.0.0.0", "FS_PORT" : 7567, - "FS_HOSTNAME" : "acs.example.com", + "FS_HOSTNAME" : "", "UI_INTERFACE" : "0.0.0.0", "UI_PORT" : 3000, "UI_JWT_SECRET": "" diff --git a/lib/config.ts b/lib/config.ts index 4095e58..bd4c754 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -62,7 +62,7 @@ const options = { FS_INTERFACE: { type: "string", default: "0.0.0.0" }, FS_SSL_CERT: { type: "string", default: "" }, FS_SSL_KEY: { type: "string", default: "" }, - FS_HOSTNAME: { type: "string", default: "acs.example.com" }, + FS_HOSTNAME: { type: "string", default: "" }, FS_LOG_FILE: { type: "path", default: "" }, FS_ACCESS_LOG_FILE: { type: "path", default: "" }, diff --git a/lib/cwmp.ts b/lib/cwmp.ts index b34f6e7..688c696 100644 --- a/lib/cwmp.ts +++ b/lib/cwmp.ts @@ -772,10 +772,15 @@ async function sendAcsRequest( downloadRequest.fileSize = 0; if (!downloadRequest.url) { const FS_PORT = config.get("FS_PORT"); - const FS_HOSTNAME = config.get("FS_HOSTNAME"); const FS_SSL = config.get("FS_SSL"); + let hostname = config.get("FS_HOSTNAME"); + if (!hostname) { + if (sessionContext.httpRequest.headers["host"]) + hostname = sessionContext.httpRequest.headers["host"].split(":")[0]; + else hostname = sessionContext.httpRequest.connection.localAddress; + } downloadRequest.url = FS_SSL ? "https://" : "http://"; - downloadRequest.url += FS_HOSTNAME; + downloadRequest.url += hostname; if (FS_PORT !== 80) downloadRequest.url += ":" + FS_PORT; downloadRequest.url += "/" + encodeURI(downloadRequest.fileName);