-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
33 lines (25 loc) · 811 Bytes
/
main.c
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 "http_server.h"
void write_res( const request *rqst, response *reply)
{
char *str = "{ \"v1\": \"redfish/v1\" }";
set_status(reply, HTTP_STATUS_OK);
set_hdr(reply, "Content-Type", "application/json");
reply->msg_len = strlen(str);
reply->msg_body = str;
}
int main() {
const int port = 8000;
http_server svc;
//bring up tls machine, this need to be done before server setup
int ng = tls_engine_inhale("server-cert.pem", "server-key.pem", 0);
assert(ng == 0);
setup_server(&svc, "0.0.0.0", port);
//the length of path passed explicitly to stop strlen calling
router *rtr = get_router(&svc);
addroute(rtr, "/redfish", 8, write_res);
printf("Listening on %d\n", port);
//run forever
run(&svc);
tls_engine_stop();
return 0;
}