-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchibiServer.c
More file actions
35 lines (29 loc) · 806 Bytes
/
chibiServer.c
File metadata and controls
35 lines (29 loc) · 806 Bytes
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
34
35
#include "chibiWeb.h"
#include "response.h"
#include "request.h"
#include "string.h"
#include "stdio.h"
Response *testHandler(Request *r) {
if (r->type == REQUEST_POST) {
char buff[100];
sprintf(buff, "body - %s", r->body);
printf("%s\n", buff);
return response_new(STATUS_200_OK, buff, strlen(buff));
}
return response_new(STATUS_200_OK, "HELLO", 5);
}
Response *dogHandler(Request *r) {
return response_new(STATUS_200_OK, "WOOF!", 5);
}
Response *indexHandler(Request *r) {
return response_new_file(STATUS_200_OK, "./static/index.html");
}
int main(int argc, char const *argv[]) {
chibi_init();
chibi_serve("/", indexHandler);
chibi_serveFiles("/static", "static/");
chibi_serve("/hello", testHandler);
chibi_serve("/dogs", dogHandler);
chibi_run(5000, 4);
return 0;
}