mirror of
https://github.com/gmod-integration/lua.git
synced 2025-03-16 01:57:34 +00:00
add: custom DQDN for API and Websocket
This commit is contained in:
parent
eb2a7a2cf3
commit
b6600612d8
|
@ -1,6 +1,3 @@
|
||||||
local websocketFQDN = "ws.gmod-integration.com"
|
|
||||||
local websocketDevFQDN = "dev-ws.gmod-integration.com"
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// WebSocket
|
// WebSocket
|
||||||
//
|
//
|
||||||
|
@ -33,7 +30,7 @@ if (!GWSockets) then
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getWebSocketURL()
|
local function getWebSocketURL()
|
||||||
return "wss://" .. (gmInte.config.devInstance and websocketDevFQDN or websocketFQDN)
|
return "wss://" .. gmInte.config.websocketFQDN
|
||||||
end
|
end
|
||||||
|
|
||||||
local socket = GWSockets.createWebSocket(getWebSocketURL())
|
local socket = GWSockets.createWebSocket(getWebSocketURL())
|
||||||
|
|
|
@ -57,7 +57,8 @@ function gmInte.publicGetConfig(ply)
|
||||||
|
|
||||||
gmInte.SendNet("publicConfig", {
|
gmInte.SendNet("publicConfig", {
|
||||||
["debug"] = gmInte.config.debug,
|
["debug"] = gmInte.config.debug,
|
||||||
["devInstance"] = gmInte.config.devInstance
|
["apiFQDN"] = gmInte.config.apiFQDN,
|
||||||
|
["websocketFQDN"] = gmInte.config.websocketFQDN,
|
||||||
}, ply)
|
}, ply)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
local apiVersion = "v3"
|
local apiVersion = "v3"
|
||||||
local apiFQDN = "api.gmod-integration.com"
|
|
||||||
local apiDevFQDN = "dev-api.gmod-integration.com"
|
|
||||||
|
|
||||||
gmInte.http = gmInte.http || {}
|
gmInte.http = gmInte.http || {}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -9,7 +6,7 @@ gmInte.http = gmInte.http || {}
|
||||||
//
|
//
|
||||||
|
|
||||||
local function getAPIURL(endpoint)
|
local function getAPIURL(endpoint)
|
||||||
local url = "https://" .. (gmInte.config.devInstance && apiDevFQDN || apiFQDN) .. "/" .. apiVersion
|
local url = "https://" .. gmInte.config.apiFQDN .. "/" .. apiVersion
|
||||||
|
|
||||||
if (SERVER) then
|
if (SERVER) then
|
||||||
url = url .. "/servers/" .. gmInte.config.id
|
url = url .. "/servers/" .. gmInte.config.id
|
||||||
|
@ -58,7 +55,7 @@ function gmInte.http.requestAPI(params)
|
||||||
local type = "application/json"
|
local type = "application/json"
|
||||||
|
|
||||||
// Log
|
// 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 ID: " .. requestID, true)
|
||||||
gmInte.log("HTTP Request: " .. method .. " " .. url, true)
|
gmInte.log("HTTP Request: " .. method .. " " .. url, true)
|
||||||
gmInte.log("HTTP Body: " .. (showableBody && body || "HIDDEN"), true)
|
gmInte.log("HTTP Body: " .. (showableBody && body || "HIDDEN"), true)
|
||||||
|
@ -76,11 +73,6 @@ function gmInte.http.requestAPI(params)
|
||||||
gmInte.log("HTTP Response: " .. code, true)
|
gmInte.log("HTTP Response: " .. code, true)
|
||||||
if (gmInte.config.debug) then gmInte.log("HTTP Body: " .. body, true) end
|
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 not application/json return failed
|
||||||
if (string.sub(headers["Content-Type"], 1, 16) != "application/json") then
|
if (string.sub(headers["Content-Type"], 1, 16) != "application/json") then
|
||||||
gmInte.log("HTTP Failed: Invalid Content-Type", true)
|
gmInte.log("HTTP Failed: Invalid Content-Type", true)
|
||||||
|
@ -90,6 +82,11 @@ function gmInte.http.requestAPI(params)
|
||||||
// Parse body
|
// Parse body
|
||||||
body = util.JSONToTable(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
|
||||||
return success(code, body)
|
return success(code, body)
|
||||||
end,
|
end,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user