aboutsummaryrefslogtreecommitdiff
path: root/main.ha
diff options
context:
space:
mode:
Diffstat (limited to 'main.ha')
-rw-r--r--main.ha22
1 files changed, 11 insertions, 11 deletions
diff --git a/main.ha b/main.ha
index b52f111..fc41240 100644
--- a/main.ha
+++ b/main.ha
@@ -2,26 +2,28 @@
// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>
// Adapted from template by Willow Barraco <contact@willowbarraco.fr>
+use fs;
use getopt;
-use htmpl;
use log;
use net;
use net::dial;
use net::http;
use net::ip;
use net::tcp;
+use net::uri;
use os;
use memio;
use io;
use fmt;
use bufio;
-use strings;
const usage: [_]getopt::help = [
"Lindenii Forge Server",
('c', "config", "path to configuration file")
];
+let static_fs: nullable *fs::fs = null;
+
export fn main() void = {
const cmd = getopt::parse(os::args, usage...);
defer getopt::finish(&cmd);
@@ -32,10 +34,12 @@ export fn main() void = {
for (let opt .. cmd.opts) {
switch (opt.0) {
case 'c' => yield; // TODO: actually handle the config
- case => abort(); // unreachable
+ case => abort("unreachable");
};
};
+ static_fs = os::diropen("static")!;
+
const server = match (http::listen(ip_addr, port, net::tcp::reuseport, net::tcp::reuseaddr)) {
case let this: *http::server =>
yield this;
@@ -47,19 +51,15 @@ export fn main() void = {
const serv_req = match (http::serve(server)) {
case let this: *http::server_request =>
yield this;
- case net::error => abort("failure while serving");
+ case =>
+ log::println("failure while serving");
+ continue;
};
defer http::serve_finish(serv_req);
match (handlereq(serv_req.socket, &serv_req.request)) {
case void => yield;
- case io::error => log::println("error while handling request");
+ case => log::println("error while handling request");
};
};
};
-
-export fn handlereq(conn: io::handle, request: *http::request) (void | io::error | nomem) = {
- htmpl::write(conn, "HTTP/1.1 200 OK\r\n")?;
- htmpl::write(conn, "Content-Type: text/html\r\n\r\n")?;
- tp_index(conn)?;
-};