Skip to content

Commit

Permalink
Closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix "xq" Queißner committed Oct 11, 2021
1 parent d8faea2 commit 39fe208
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -117,7 +117,7 @@ Includes a teeny tiny web server for debugging.
zig build install run-wasm
```

Now visit http://127.0.0.1:8000/index.htm to see the demo.
Now visit http://127.0.0.1:8000/demo_application.htm to see the demo.

### Android

2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
@@ -98,10 +98,10 @@ pub fn build(b: *std.build.Builder) !void {
});

const serve = server.run();
serve.addArg(app.name);
serve.step.dependOn(&wasm_build.data.web.install_step.?.step);

const run_step = b.step("run-wasm", "Serves the wasm app");

run_step.dependOn(&serve.step);
}

19 changes: 16 additions & 3 deletions tools/http-server.zig
Original file line number Diff line number Diff line change
@@ -4,19 +4,32 @@ const file_server = http.FileServer;

pub const io_mode = .evented;

pub fn main() !void {
pub fn main() !u8 {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = &gpa.allocator;

try file_server.init(allocator, .{ .dir_path = "www" });
const args = try std.process.argsAlloc(allocator);
defer std.process.argsFree(allocator, args);

if (args.len != 2) {
std.log.err("Missing argument: Application name!", .{});
return 1;
}

const application_name = args[1];

try file_server.init(allocator, .{ .dir_path = "zig-out/www" });
defer file_server.deinit();

std.log.info("Application is now served at http://127.0.0.1:8000/index.htm", .{});
std.log.info("Application is now served at http://127.0.0.1:8000/{s}.htm", .{application_name});

try http.listenAndServe(
allocator,
try std.net.Address.parseIp("127.0.0.1", 8000),
{},
file_server.serve,
);

return 0;
}

0 comments on commit 39fe208

Please sign in to comment.