-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
152 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,37 @@ | ||
const std = @import("std"); | ||
const w = @import("worker"); | ||
const io = std.io; | ||
const http = std.http; | ||
const worker = @import("worker"); | ||
|
||
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); | ||
const allocator = arena.allocator(); | ||
|
||
// Not working with *http.Server.Response | ||
// fn cool(resp: *http.Server.Response, r: *http.Client.Request) void { | ||
fn requestFn(resp: *worker.Response, r: *http.Client.Request) void { | ||
_ = r; | ||
std.debug.print("Hello from function\n", .{ }); | ||
|
||
// std.debug.print("+++ doing payload \n", .{ }); | ||
// var payload: []const u8 = ""; | ||
// var reqBody = r.reader().readAllAlloc(allocator, 8192) catch unreachable; | ||
// defer allocator.free(reqBody); | ||
|
||
// if (reqBody.len == 0) { | ||
// payload = "-"; | ||
// } else { | ||
// payload = reqBody; | ||
// } | ||
// std.debug.print("+++ finished payload \n", .{ }); | ||
|
||
// var resp = r.response; | ||
|
||
_ = &resp.httpHeader.append("content-type", "text/plain"); | ||
_ = &resp.httpHeader.append("x-generated-by", "wasm-workers-server"); | ||
|
||
_ = &resp.writeAll("Zig World!"); | ||
} | ||
|
||
pub fn main() !void { | ||
var word = w.GetWord(); | ||
std.debug.print("Hello from {s}!\n", .{ word }); | ||
} | ||
worker.ServeFunc(requestFn); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters