Http module in prosody plugin

I am working on a prosody module and in that I have created some API end points. But I am unable to access them with curl.

    module:depends("http");
    module:provides("http", {
        default_path = "/",
        route = {
            ["GET room-max-participants"] = function(event)
                return async_handler_wrapper(event, handle_get_max_occupants)
            end,
            ["SET room-max-participants"] = function(event)
                return async_handler_wrapper(event, handle_set_max_occupants)
            end
        }
    });

And

curl http://localhost:5280/room-max-participants is returning 404 error.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>404 Not Found</title>
<style>
body{
	margin-top:14%;
	text-align:center;
	background-color:#F8F8F8;
	font-family:sans-serif;
}
h1{
	font-size:xx-large;
}
p{
	font-size:x-large;
}
p+p {
	font-size:large;
	font-family:courier;
}
</style>
</head>
<body>
<h1>404 Not Found</h1>
<p>Whatever you were looking for is not here. Keep looking.</p>
<p>Unknown host: localhost</p>
</body>
</html>

Please help me resolving the issue.

Try turning on debug mode and see messages to see to which domain those endpoints are attached to, apparently, you don’t have a hostname localhost defined in prosody.

Here are the logs for the curl command

Jan 08 06:37:00 socket  debug   server.lua: accepted new client connection from 127.0.0.1:36246 to 5280
Jan 08 06:37:00 http.server debug   Firing event: GET /room-max-participants
Jan 08 06:37:00 socket  debug   server.lua: client 127.0.0.1:36246 read error: closed
Jan 08 06:37:00 socket  debug   server.lua: closed client handler and removed socket from list

/etc/prosody/conf.avail has 2 lua configuration file.

  1. localhost.cfg.lua

    -- Section for localhost
    
    -- This allows clients to connect to localhost. No harm in it.
    VirtualHost "localhost"
    
  2. jitsi.ourdomain.com.cfg.lua

    VirtualHost "jitsi.ourdomain.com"
            ssl = {
                    key = "/etc/prosody/certs/jitsi.ourdomain.com.key";
                    certificate = "/etc/prosody/certs/jitsi.ourdomain.com.crt";
            }
            -- other config
            modules_enabled = {
                "bosh";
                "websocket";
                ... --other plugins
                "http";
            }
            c2s_require_encryption = false
            lobby_muc = "lobby.jitsi.ourdomain.com"
            main_muc = "conference.jitsi.ourdomain.com"
        ```
    
    

And https is enabled on the ourdomain.

Have you tried
curl http://jitsi.ourdomain.com:5280/room-max-participants?
Or if you can set the curl command the host header to your domain then the localhost url will also work.

Here are the outputs for given commands.

  1. domain with http

    curl http://jitsi.ourdomain.com:5280/room-max-participants

    curl: (7) Failed to connect to jitsi.ourdomain.com port 5280: Connection refused

  2. domain with https

    curl https://jitsi.ourdomain.com:5281/room-max-participants

    curl: (7) Failed to connect to jitsi.ourdomain.com port 5281: Connection refused

  3. Passing host header into the localhost

    curl -H ‘Host:jitsi.ourdomain.com’ http://localhost:5280/room-max-participants

        <!DOCTYPE html>
        <html>
        <head>
        <meta charset="utf-8">
        <title>404 Not Found</title>
        <style>
        body{
            margin-top:14%;
            text-align:center;
            background-color:#F8F8F8;
            font-family:sans-serif;
        }
        h1{
            font-size:xx-large;
        }
        p{
            font-size:x-large;
        }
        p+p {
            font-size:large;
            font-family:courier;
        }
        </style>
        </head>
        <body>
        <h1>404 Not Found</h1>
        <p>Whatever you were looking for is not here. Keep looking.</p>
        <p></p>
        </body>
        </html>
    

    In this case, error message is empty on passing host header as “jitsi.ourdomain.com”, but for any other value, it is returning the same error (i.e “Unknown host”)

is your module enabled under the jitsi.ourdomain.com virtual host?

yes, the module is enabled, other functions and hooks working fine.

But I’m asking where it is enabled? As I don’t see it under the virtualhost config, it should be there.

We have enabled it under conference component.

Component "conference.jitsi.ourdomain.com" "muc"
    storage = "memory"
    modules_enabled = {
        "muc_meeting_id";
        "muc_domain_mapper";
        -- "token_verification";
	    "muc_max_occupants";
    }
    muc_max_occupants = "10";
    muc_access_whitelist = { "focus@auth.jitsi.ourdomain.com"}
    admins = { "focus@auth.jitsi.ourdomain.com" }
    muc_room_locking = false
    muc_room_default_public_jids = true
    main_muc = "conference.jitsi.ourdomain.com"

So you have added your code in any of the existing modules … ?
If the code is under the muc component … I think then the Host header you set to curl must be ‘conference.jitsi.ourdomain.com’.

@damencho,
Yes, I have added the code in muc_max_occupants plugin.
Even I tried with host header as " ‘conference.jitsi.ourdomain.com’, still it is throwing the same error as ‘jitst.ourdomain.com’(i.e 404 error with empty error message)

Please help me in resolving the issue. I am new into this.

Try it under the main virtual host.