Diagnostic tool: testing API communication between Peertube and Prosody.
This commit is contained in:
5
prosody-modules/mod_http_peertubelivechat_test/README.md
Normal file
5
prosody-modules/mod_http_peertubelivechat_test/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# mod_http_peertubelivechat_test
|
||||
|
||||
This module is a custom module that allows Peertube to test communication with Prosody.
|
||||
|
||||
This module is part of peertube-plugin-livechat, and is under the same LICENSE.
|
@ -0,0 +1,43 @@
|
||||
local json = require "util.json";
|
||||
|
||||
module:depends"http";
|
||||
|
||||
function check_auth(routes)
|
||||
local function check_request_auth(event)
|
||||
local apikey = module:get_option_string("peertubelivechat_test_apikey", "")
|
||||
if apikey == "" then
|
||||
return false, 500;
|
||||
end
|
||||
if event.request.headers.authorization ~= "Bearer " .. apikey then
|
||||
return false, 401;
|
||||
end
|
||||
return true;
|
||||
end
|
||||
|
||||
for route, handler in pairs(routes) do
|
||||
routes[route] = function (event, ...)
|
||||
local permit, code = check_request_auth(event);
|
||||
if not permit then
|
||||
return code;
|
||||
end
|
||||
return handler(event, ...);
|
||||
end;
|
||||
end
|
||||
return routes;
|
||||
end
|
||||
|
||||
local function test_peertube_prosody(event)
|
||||
local request, response = event.request, event.response;
|
||||
local json_response = {
|
||||
ok = true;
|
||||
}
|
||||
event.response.headers["Content-Type"] = "application/json";
|
||||
return json.encode(json_response);
|
||||
end
|
||||
|
||||
module:provides("http", {
|
||||
route = check_auth {
|
||||
["GET /test-peertube-prosody"] = test_peertube_prosody;
|
||||
-- ["GET /test-prosody-peertube"] = test_prosody_peertube;
|
||||
};
|
||||
});
|
Reference in New Issue
Block a user