|
1 | 1 | //!Serve a Folder Example |
2 | 2 | const std = @import("std"); |
3 | 3 | const webui = @import("webui"); |
| 4 | +const test_txt = @embedFile("test.txt"); |
| 5 | +const dynamic_txt = @embedFile("dynamic.txt"); |
4 | 6 |
|
5 | 7 | var MyWindow: webui = undefined; |
6 | 8 | var MySecondWindow: webui = undefined; |
@@ -102,30 +104,15 @@ fn my_files_handler(filename: []const u8) ?[]const u8 { |
102 | 104 |
|
103 | 105 | if (std.mem.eql(u8, filename, "/test.txt")) { |
104 | 106 | // Const static file example |
105 | | - return |
106 | | - \\HTTP/1.1 200 OK |
107 | | - \\Content-Type: text/html |
108 | | - \\Content-Length: 99 |
109 | | - \\ |
110 | | - \\<html> |
111 | | - \\ This is a static embedded file content example. |
112 | | - \\ <script src="webui.js"></script> |
113 | | - \\</html> |
114 | | - ; |
| 107 | + return test_txt; |
115 | 108 | } else if (std.mem.eql(u8, filename, "/dynamic.html")) { |
116 | 109 | const body = webui.malloc(1024); |
117 | 110 | defer webui.free(body); |
118 | 111 | const header_and_body = webui.malloc(1024); |
119 | 112 |
|
120 | 113 | count += 1; |
121 | 114 |
|
122 | | - const buf = std.fmt.bufPrint(body, |
123 | | - \\<html> |
124 | | - \\ This is a dynamic file content example. <br> |
125 | | - \\ Count: {} <a href="dynamic.html">[Refresh]</a><br> |
126 | | - \\ <script src="/webui.js"></script> |
127 | | - \\</html> |
128 | | - , .{count}) catch unreachable; |
| 115 | + const buf = std.fmt.bufPrint(body, dynamic_txt, .{count}) catch unreachable; |
129 | 116 |
|
130 | 117 | const content = std.fmt.bufPrint(header_and_body, |
131 | 118 | \\HTTP/1.1 200 OK |
|
0 commit comments