mirror of
https://github.com/zigzap/zap.git
synced 2025-10-20 15:14:08 +00:00
improved hello example
This commit is contained in:
parent
aa1bd024bf
commit
e238a5d9ea
1 changed files with 7 additions and 17 deletions
|
@ -1,27 +1,17 @@
|
|||
const std = @import("std");
|
||||
const zap = @import("zap");
|
||||
|
||||
fn on_request(request: [*c]zap.C.http_s) callconv(.C) void {
|
||||
std.debug.print("GOT A REQUEST!\n", .{});
|
||||
// std.time.sleep(5 * 1000 * 1000);
|
||||
_ = zap.sendBody(request, "Hello from ZAP!!!");
|
||||
fn on_request(r: [*c]zap.C.http_s) callconv(.C) void {
|
||||
_ = zap.sendBody(r, "<html><body><h1>Hello from ZAP!!!</h1></body></html>");
|
||||
}
|
||||
|
||||
pub fn main() !void {
|
||||
// std.debug.print("debug1\n", .{});
|
||||
// configure
|
||||
var listen_settings: zap.ListenSettings = .{};
|
||||
// std.debug.print("debug2\n", .{});
|
||||
listen_settings.on_request = on_request;
|
||||
listen_settings.log = true;
|
||||
|
||||
// std.debug.print("debug3\n", .{});
|
||||
|
||||
// listen
|
||||
try zap.listen("3000", null, listen_settings);
|
||||
std.debug.print("Listening on port 3000\n", .{});
|
||||
|
||||
// std.debug.print("debug4\n", .{});
|
||||
try zap.listen("3000", null, .{
|
||||
.on_request = on_request,
|
||||
.log = true,
|
||||
});
|
||||
std.debug.print("Listening on 0.0.0.0:3000\n", .{});
|
||||
|
||||
// start working
|
||||
zap.start(.{
|
||||
|
|
Loading…
Add table
Reference in a new issue