mach: build+tools: allow address and port of http server be configurable
for wasm MACH_ADDRESS and MACH_PORT environment variable are added.
This commit is contained in:
parent
8b8ed4dc8f
commit
8d4c51738e
2 changed files with 16 additions and 4 deletions
|
|
@ -12,14 +12,23 @@ pub fn main() !u8 {
|
|||
const args = try std.process.argsAlloc(allocator);
|
||||
defer std.process.argsFree(allocator, args);
|
||||
|
||||
std.debug.print("Served at http://127.0.0.1:8000/{s}.html\n", .{args[1]});
|
||||
if (args.len < 4) {
|
||||
std.debug.print("Usage: http-server <application-name> <address> <port>\n", .{});
|
||||
return 0;
|
||||
}
|
||||
|
||||
const application_name = args[1];
|
||||
const address = args[2];
|
||||
const port = try std.fmt.parseUnsigned(u16, args[3], 10);
|
||||
|
||||
std.debug.print("Served at http://{s}:{}/{s}.html\n", .{ address, port, application_name });
|
||||
|
||||
try file_server.init(allocator, .{ .dir_path = "." });
|
||||
defer file_server.deinit();
|
||||
|
||||
try http.listenAndServe(
|
||||
allocator,
|
||||
try std.net.Address.parseIp("127.0.0.1", 8000),
|
||||
try std.net.Address.parseIp(address, port),
|
||||
{},
|
||||
file_server.serve,
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue