mirror of
https://github.com/opus-tango/http-server-in-c.git
synced 2026-03-20 03:55:25 +00:00
enable additional file types and add demo files
This commit is contained in:
BIN
public/image.jpg
Normal file
BIN
public/image.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
14
public/includetest.html
Normal file
14
public/includetest.html
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Document</title>
|
||||||
|
<link rel="stylesheet" href="index.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root">
|
||||||
|
<h1>Demo page</h1>
|
||||||
|
<p>If you are seeing this then the server is working :)</p>
|
||||||
|
<!-- <<LINKS>> -->
|
||||||
|
</div>
|
||||||
|
<script src="script.js"></script>
|
||||||
|
</body>
|
||||||
27
public/index.css
Normal file
27
public/index.css
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
#root {
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
background-color: aqua;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
}
|
||||||
@@ -31,6 +31,7 @@
|
|||||||
<div id="root">
|
<div id="root">
|
||||||
<h1>Demo page</h1>
|
<h1>Demo page</h1>
|
||||||
<p>If you are seeing this then the server is working :)</p>
|
<p>If you are seeing this then the server is working :)</p>
|
||||||
|
<p><a href="/includetest.html">Click here</a> to see an example of including css and js as separate files</p>
|
||||||
<!-- <<LINKS>> -->
|
<!-- <<LINKS>> -->
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
4
public/script.js
Normal file
4
public/script.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
const button = document.createElement('button');
|
||||||
|
button.textContent = 'Click me!';
|
||||||
|
button.onclick = () => alert('You clicked the button!');
|
||||||
|
document.body.appendChild(button);
|
||||||
@@ -16,16 +16,13 @@ void response_handle_get(http_request* req, http_response* res) {
|
|||||||
if (strcmp(ptr, ".html") == 0) {
|
if (strcmp(ptr, ".html") == 0) {
|
||||||
response_build_static_file(file_path, HTML, OK, res);
|
response_build_static_file(file_path, HTML, OK, res);
|
||||||
} else if (strcmp(ptr, ".jpg") == 0) {
|
} else if (strcmp(ptr, ".jpg") == 0) {
|
||||||
serve_404(res);
|
response_build_static_file(file_path, JPG, OK, res);
|
||||||
return;
|
|
||||||
} else if (strcmp(ptr, ".png") == 0) {
|
} else if (strcmp(ptr, ".png") == 0) {
|
||||||
response_build_static_file(file_path, PNG, OK, res);
|
response_build_static_file(file_path, PNG, OK, res);
|
||||||
} else if (strcmp(ptr, ".css") == 0) {
|
} else if (strcmp(ptr, ".css") == 0) {
|
||||||
serve_404(res);
|
response_build_static_file(file_path, CSS, OK, res);
|
||||||
return;
|
|
||||||
} else if (strcmp(ptr, ".js") == 0) {
|
} else if (strcmp(ptr, ".js") == 0) {
|
||||||
serve_404(res);
|
response_build_static_file(file_path, JS, OK, res);
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
serve_404(res);
|
serve_404(res);
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user