Semi-dynamic routing
This commit is contained in:
14
main.c
14
main.c
@@ -7,6 +7,8 @@
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define DEFAULT_HTML "index.html"
|
||||
|
||||
int main() {
|
||||
|
||||
const int PORT = 8080;
|
||||
@@ -50,11 +52,17 @@ int main() {
|
||||
1024 - 1); // subtract 1 for the null
|
||||
// terminator at the end
|
||||
HttpRequest *req = handle_request(request);
|
||||
// print_request(req);
|
||||
HttpResponse *res = from_file("./index.html");
|
||||
HttpResponse *res;
|
||||
if (!strcmp(req->path, "/")) {
|
||||
res = from_file("./" DEFAULT_HTML);
|
||||
} else {
|
||||
char path[] = ".";
|
||||
strcat(path, req->path);
|
||||
res = from_file(path);
|
||||
}
|
||||
free(req);
|
||||
http_respond(*res, clientfd);
|
||||
free_response(res);
|
||||
printf("Hello message sent\n");
|
||||
|
||||
// closing the connected socket
|
||||
close(clientfd);
|
||||
|
||||
Reference in New Issue
Block a user