-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
51 lines (39 loc) · 1.15 KB
/
test.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Run with `make run` from root of `libexpress`. Make sure all dependencies
// are install first.
#include <libexpress/express.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#undef __BASE__
#define __BASE__ "/home/resyfer/self/projects/libexpress/examples" // Give your own directories here
void frontend(req_t *req, res_t *res) {
res_send_file(res, __BASE__ "/index.html");
}
void adios(req_t *req, res_t *res) {
char *file = get_req_param(req, "file");
char path[PATH_MAX] = {0};
sprintf(path, "%s/%s", __BASE__, file);
res_send_file(res, path);
}
void blah(req_t *req, res_t *res) {
set_res_body(res, get_req_param(req, "id"));
res_send(res);
}
void hi(req_t *req, res_t *res) {
set_res_body(res, "Hi\n");
res_send(res);
}
void middle(req_t *req, res_t *res) {
printf("Middle\n");
}
int main() {
server_t *app = server_new();
route_get(app, "/hello", middle, MID_END, hi);
route_get(app, "/hello/bye", MID_END, hi);
route_get(app, "/:file", MID_END, adios);
route_get(app, "/", MID_END, NULL);
route(app, "/foo", "*", MID_END, frontend);
route_post(app, "/hello/:id/world", MID_END, blah);
server_listen(app, 3000);
return 0;
}