add: custom DQDN for API and Websocket

This commit is contained in:
Linventif 2024-02-28 18:39:52 +01:00
parent eb2a7a2cf3
commit b6600612d8
No known key found for this signature in database
GPG Key ID: FAC0CA60F9AEEC24
3 changed files with 10 additions and 15 deletions

View File

@ -1,6 +1,3 @@
local websocketFQDN = "ws.gmod-integration.com"
local websocketDevFQDN = "dev-ws.gmod-integration.com"
//
// WebSocket
//
@ -33,7 +30,7 @@ if (!GWSockets) then
end
local function getWebSocketURL()
return "wss://" .. (gmInte.config.devInstance and websocketDevFQDN or websocketFQDN)
return "wss://" .. gmInte.config.websocketFQDN
end
local socket = GWSockets.createWebSocket(getWebSocketURL())

View File

@ -57,7 +57,8 @@ function gmInte.publicGetConfig(ply)
gmInte.SendNet("publicConfig", {
["debug"] = gmInte.config.debug,
["devInstance"] = gmInte.config.devInstance
["apiFQDN"] = gmInte.config.apiFQDN,
["websocketFQDN"] = gmInte.config.websocketFQDN,
}, ply)
end

View File

@ -1,7 +1,4 @@
local apiVersion = "v3"
local apiFQDN = "api.gmod-integration.com"
local apiDevFQDN = "dev-api.gmod-integration.com"
gmInte.http = gmInte.http || {}
//
@ -9,7 +6,7 @@ gmInte.http = gmInte.http || {}
//
local function getAPIURL(endpoint)
local url = "https://" .. (gmInte.config.devInstance && apiDevFQDN || apiFQDN) .. "/" .. apiVersion
local url = "https://" .. gmInte.config.apiFQDN .. "/" .. apiVersion
if (SERVER) then
url = url .. "/servers/" .. gmInte.config.id
@ -58,7 +55,7 @@ function gmInte.http.requestAPI(params)
local type = "application/json"
// Log
if (gmInte.config.devInstance) then gmInte.log("HTTP Using dev Instance", true) end
gmInte.log("HTTP FQDN: " .. gmInte.config.apiFQDN, true)
gmInte.log("HTTP Request ID: " .. requestID, true)
gmInte.log("HTTP Request: " .. method .. " " .. url, true)
gmInte.log("HTTP Body: " .. (showableBody && body || "HIDDEN"), true)
@ -76,11 +73,6 @@ function gmInte.http.requestAPI(params)
gmInte.log("HTTP Response: " .. code, true)
if (gmInte.config.debug) then gmInte.log("HTTP Body: " .. body, true) end
// if not 2xx return failed
if (code < 200 || code >= 300) then
return failed(body, code, headers)
end
// if not application/json return failed
if (string.sub(headers["Content-Type"], 1, 16) != "application/json") then
gmInte.log("HTTP Failed: Invalid Content-Type", true)
@ -90,6 +82,11 @@ function gmInte.http.requestAPI(params)
// Parse body
body = util.JSONToTable(body || "{}")
// if not 2xx return failed
if (code < 200 || code >= 300) then
return failed(code, body, headers)
end
// Return success
return success(code, body)
end,