Something went wrong. Try again.
🦦 a tiny cute lua web framework
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263const std = @import("std");
const fern = @import("fern");const options = @import("options");
const Self = @This();
root: []const u8,// root for html files, defaults to `root + "build"`buildroot: []const u8,// root for lua modules, defaults to `root + "lua"`luaroot: []const u8,// root for static assets, defaults to `root + "static"`staticroot: []const u8,// maivi runtime pathruntime: []const u8,
log_level: fern.Level = .info,base_url: []const u8,port: u16,
pub fn init(io: std.Io, arena: *std.heap.ArenaAllocator, environ_map: *std.process.Environ.Map) !Self { const allocator = arena.allocator();
const cwd = try std.Io.Dir.cwd().realPathFileAlloc(io, ".", allocator);
const port_env = if (environ_map.get("MAIVI_PORT")) |p| try std.fmt.parseInt(u16, p, 10) else null; const port = port_env orelse 5882; const default_base_url = try std.fmt.allocPrint(allocator, "http://127.0.0.1:{d}", .{port});
const root = environ_map.get("MAIVI_ROOT") orelse cwd; const default_buildroot = try std.mem.join(allocator, "/", &.{ root, "build" }); const default_luaroot = try std.mem.join(allocator, "/", &.{ root, "lua" }); const default_staticroot = try std.mem.join(allocator, "/", &.{ root, "static" });
return .{ .root = root, .buildroot = environ_map.get("MAIVI_BUILD") orelse default_buildroot, .luaroot = environ_map.get("MAIVI_LUA") orelse default_luaroot, .staticroot = environ_map.get("MAIVI_STATIC") orelse default_staticroot, .runtime = environ_map.get("MAIVI_RUNTIME") orelse options.runtimepath, .log_level = if (environ_map.get("MAIVI_LOG")) |env| if (std.mem.eql(u8, env, "fatal")) .fatal else if (std.mem.eql(u8, env, "error")) .err else if (std.mem.eql(u8, env, "warn")) .warn else if (std.mem.eql(u8, env, "info")) .info else if (std.mem.eql(u8, env, "debug")) .debug else if (std.mem.eql(u8, env, "off")) .off else .info else .info, .base_url = environ_map.get("MAIVI_BASE_URL") orelse default_base_url, .port = port, };}