aboutsummaryrefslogtreecommitdiff
path: root/packages/bun-uws/capi/examples/HelloWorld.c
blob: 613ba593475ea48b746900543fd11e86ba1892db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "../libuwebsockets.h"
#include "libusockets.h"
#include <stdio.h>

#define SSL 1

void get_handler(uws_res_t *res, uws_req_t *req, void *user_data)
{
    uws_res_end(SSL, res, "Hello CAPI!", 11, false);
}

void listen_handler(struct us_listen_socket_t *listen_socket, uws_app_listen_config_t config, void *user_data)
{
    if (listen_socket)
    {
        printf("Listening on port https://localhost:%d now\n", config.port);
    }
}

int main()
{
    /* Overly simple hello world app */

    uws_app_t *app = uws_create_app(SSL, (struct us_socket_context_options_t){
        /* There are example certificates in uWebSockets.js repo */
	    .key_file_name = "../misc/key.pem",
	    .cert_file_name = "../misc/cert.pem",
	    .passphrase = "1234"
    });
    uws_app_get(SSL, app, "/*", get_handler, NULL);
    uws_app_listen(SSL, app, 3000, listen_handler, NULL);
    uws_app_run(SSL, app);
}