-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.c
41 lines (25 loc) · 871 Bytes
/
app.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "include/socked.h"
void handle_index(Sc_Request *req, Sc_Response *res) {
sc_set_header(res, "Content-Type", "text/html");
sc_set_body_file(res, "www/index.html");
}
void handle_script(Sc_Request *req, Sc_Response *res) {
sc_set_header(res, "Content-Type", "application/javascript");
sc_set_body_file(res, "www/script.js");
}
int main() {
Sc_Server *socked_server = sc_server();
// sc_get(socked_server, "/", &handle_index);
// sc_get(socked_server, "/index.html", &handle_index);
// sc_get(socked_server, "/script.js", &handle_script);
sc_static(socked_server, "/a/b", "www");
/*
GET /a/b HTTP/1.1 -> www/index.html
GET /a/b/script.js HTTP/1.1 -> www/script.js
*/
sc_listen(socked_server, "127.0.0.1", 8080);
}