diff --git a/build.zig b/build.zig
index ceb4588..d7cd8ae 100644
--- a/build.zig
+++ b/build.zig
@@ -22,7 +22,6 @@ pub fn build(b: *std.Build) !void {
.root_source_file = b.path("src/jetzig.zig"),
.target = target,
.optimize = optimize,
- .use_llvm = false,
});
const mime_module = try GenerateMimeTypes.generateMimeModule(b);
@@ -37,6 +36,7 @@ pub fn build(b: *std.Build) !void {
.{
.target = target,
.optimize = optimize,
+ .use_llvm = b.option(bool, "use_llvm", "Use LLVM") orelse false,
.zmpl_templates_paths = templates_paths,
.zmpl_auto_build = false,
.zmpl_markdown_fragments = try generateMarkdownFragments(b),
@@ -92,18 +92,6 @@ pub fn build(b: *std.Build) !void {
jetzig_module.addImport("smtp", smtp_client_dep.module("smtp_client"));
jetzig_module.addImport("httpz", httpz_dep.module("httpz"));
- const websockets_exe = b.addExecutable(.{
- .name = "websockets",
- .root_source_file = b.path("websockets/main.zig"),
- .optimize = optimize,
- .target = target,
- .use_llvm = false,
- });
- websockets_exe.root_module.addImport("httpz", httpz_dep.module("httpz"));
- const run_websockets_exe = b.addRunArtifact(websockets_exe);
- const websockets_step = b.step("websockets", "Launch development websockets server");
- websockets_step.dependOn(&run_websockets_exe.step);
-
const main_tests = b.addTest(.{
.root_source_file = b.path("src/tests.zig"),
.target = target,
diff --git a/build.zig.zon b/build.zig.zon
index e239d14..e45c3b9 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -6,6 +6,10 @@
.url = "https://github.com/jetzig-framework/zmd/archive/d6c8aa9a9cde99674ccb096d8f94ed09cba8dab.tar.gz",
.hash = "1220d0e8734628fd910a73146e804d10a3269e3e7d065de6bb0e3e88d5ba234eb163",
},
+ .zmpl = .{
+ .url = "https://github.com/jetzig-framework/zmpl/archive/c003d99547154e7172d1e4d3a85e8424187729d5.tar.gz",
+ .hash = "12208686edfa397975c841bc5bae095f0903bf9289681ca6d704cef7e4b6c6d04a46",
+ },
.jetkv = .{
.url = "https://github.com/jetzig-framework/jetkv/archive/9d754e552e7569239a900ed9e0f313a0554ed2d3.tar.gz",
.hash = "122013f8596bc615990fd7771c833cab4d2959ecac8d05c4f6c973aa46624e43afea",
@@ -38,10 +42,6 @@
.url = "https://github.com/jetzig-framework/jetquery/archive/d4010cfd9ced2e7deb0f3a6cc64e2d32b8db95ba.tar.gz",
.hash = "122069eeb0d43931e49f93419bdb5930ac3a6bc35d1e977738fe872ecaac8ff32aec",
},
- .zmpl = .{
- .url = "https://github.com/jetzig-framework/zmpl/archive/b1dfca8eec73520af5b029016c5b5914da659b6d.tar.gz",
- .hash = "1220e70c218c89de219d4f9506a4ad69bd1b5257cd8c7cdc2ea823830e1d8b9dc4df",
- },
},
.paths = .{
diff --git a/cli/commands/server.zig b/cli/commands/server.zig
index f9ae394..482c5c1 100644
--- a/cli/commands/server.zig
+++ b/cli/commands/server.zig
@@ -77,6 +77,7 @@ pub fn run(
"on",
});
+ _ = cwd.createFile("src/routes.zig", .{}) catch {};
var exe_path = try util.locateExecutable(allocator, cwd, .{});
const stat = try std.fs.cwd().statFile(exe_path.?);
var mtime = stat.mtime;
@@ -91,13 +92,6 @@ pub fn run(
std.process.exit(1);
};
- util.runCommandInDir(
- allocator,
- &.{ "zig", "build", "websockets" },
- .{ .path = realpath },
- .{ .output = .stream, .wait = false },
- );
-
var zmpl_thread = try std.Thread.spawn(
.{ .allocator = allocator },
zmplThread,
diff --git a/demo/.gitignore b/demo/.gitignore
index 1ddcd8a..0d1d8f7 100644
--- a/demo/.gitignore
+++ b/demo/.gitignore
@@ -4,3 +4,4 @@ static/
src/app/views/**/.*.zig
.DS_Store
log/
+src/routes.zig
diff --git a/demo/src/app/views/channels.zig b/demo/src/app/views/channels.zig
deleted file mode 100644
index 0d75d76..0000000
--- a/demo/src/app/views/channels.zig
+++ /dev/null
@@ -1,16 +0,0 @@
-const std = @import("std");
-const jetzig = @import("jetzig");
-
-pub fn index(request: *jetzig.Request) !jetzig.View {
- var channel = try request.server.channels.acquire("my-channel");
- _ = &channel;
- return request.render(.ok);
-}
-
-test "index" {
- var app = try jetzig.testing.app(std.testing.allocator, @import("routes"));
- defer app.deinit();
-
- const response = try app.request(.GET, "/channels", .{});
- try response.expectStatus(.ok);
-}
diff --git a/demo/src/app/views/root.zig b/demo/src/app/views/root.zig
index f878fc4..59eb7ea 100644
--- a/demo/src/app/views/root.zig
+++ b/demo/src/app/views/root.zig
@@ -12,7 +12,7 @@ pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View {
try root.put("imported_number", importedFunction(100, 200, 300));
try request.response.headers.append("x-example-header", "example header value");
- try root.put("foobar", "hello");
+ try root.put("foobar", "YIKES");
try request.server.logger.INFO("data", .{});
return request.render(.ok);
diff --git a/demo/src/app/views/root/index.zmpl b/demo/src/app/views/root/index.zmpl
index fc9fb0c..532ca14 100644
--- a/demo/src/app/views/root/index.zmpl
+++ b/demo/src/app/views/root/index.zmpl
@@ -1,11 +1,11 @@
HELLO
-SPEED
-SPEED
-SPEED
-SPEED
-SPEED
-SPEED
+HI THERE
+BOOP
+BLAP
+BLAPPPPP
+CAHCHACA
+YAY
SPEED
SPEED
SPEED
diff --git a/demo/src/main.zig b/demo/src/main.zig
index b4a542b..26f638a 100644
--- a/demo/src/main.zig
+++ b/demo/src/main.zig
@@ -16,7 +16,6 @@ pub const jetzig_options = struct {
// jetzig.middleware.AntiCsrfMiddleware,
// jetzig.middleware.HtmxMiddleware,
// jetzig.middleware.CompressionMiddleware,
- jetzig.middleware.HotReloadMiddleware,
// @import("app/middleware/DemoMiddleware.zig"),
};
diff --git a/demo/src/routes.zig b/demo/src/routes.zig
index aed6906..b343955 100644
--- a/demo/src/routes.zig
+++ b/demo/src/routes.zig
@@ -2,7 +2,7 @@ const jetzig = @import("jetzig");
pub const routes = [_]jetzig.Route{
.{
- .id = "AkI5YOzDJzuODxAPp4VDCIVTHlk9K9Et",
+ .id = "RGJmKq1nsYnrukQaUGcnAqG3LM69qElM",
.name = "nested_route_example_get",
.action = .get,
.view_name = "nested/route/example",
@@ -19,7 +19,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/nested/route/example.zig"), "formats")) @import("app/views/nested/route/example.zig").formats else null,
},
.{
- .id = "jyCCfxQ3gWI07OyKkz0DLuoSLZ2uWsvn",
+ .id = "RQDXM6y9q0VMbtChKtBoTdBKLPDfx33A",
.name = "static_get",
.action = .get,
.view_name = "static",
@@ -36,7 +36,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/static.zig"), "formats")) @import("app/views/static.zig").formats else null,
},
.{
- .id = "MlnUk52uBuoQ8I2ew86bRMYagC7VNadv",
+ .id = "cIJuzHGbXDXHd0zVrh0tqxSsmXWjfQlE",
.name = "static_index",
.action = .index,
.view_name = "static",
@@ -53,7 +53,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/static.zig"), "formats")) @import("app/views/static.zig").formats else null,
},
.{
- .id = "GzljS2WHIvOPF5ods7cdqJfSY9OXbTs4",
+ .id = "fuafLMIkCJWCy4NuuMM5dgNov4my1D4x",
.name = "session_edit",
.action = .edit,
.view_name = "session",
@@ -69,7 +69,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/session.zig"), "formats")) @import("app/views/session.zig").formats else null,
},
.{
- .id = "BSi50qh31yc8kS5YBMzyXxyWoq0BbjYj",
+ .id = "GmsGF6AS9G6s2MgpNdDHpo0nP0ea9HF2",
.name = "root_edit",
.action = .edit,
.view_name = "root",
@@ -85,7 +85,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/root.zig"), "formats")) @import("app/views/root.zig").formats else null,
},
.{
- .id = "Hzfw3GrABWhP1R3wA5Ix6M2QGuL733Bh",
+ .id = "tupJPgayfGiMxm01T2wbSqhV5eV1t9Cj",
.name = "format_get",
.action = .get,
.view_name = "format",
@@ -101,7 +101,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/format.zig"), "formats")) @import("app/views/format.zig").formats else null,
},
.{
- .id = "dbkt77CflbzPEri3c1uo5U4AGhtlC3Jn",
+ .id = "TTE41AX5C09LyTILQLIEnZx7fJzVRZbS",
.name = "quotes_get",
.action = .get,
.view_name = "quotes",
@@ -117,7 +117,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/quotes.zig"), "formats")) @import("app/views/quotes.zig").formats else null,
},
.{
- .id = "Qgc7WwR2psbexSNcrljPqUSw5rmY3g8x",
+ .id = "qcuSLMzQAAYMN64rNV0FVn2vJb7x3d3K",
.name = "background_jobs_index",
.action = .index,
.view_name = "background_jobs",
@@ -133,7 +133,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/background_jobs.zig"), "formats")) @import("app/views/background_jobs.zig").formats else null,
},
.{
- .id = "KJOP1zzGpWfvCTIcmVNw3CSNWG4g0zY0",
+ .id = "fEIpVaQxdC5780a36HbqR7Hq56phPaWl",
.name = "session_index",
.action = .index,
.view_name = "session",
@@ -149,7 +149,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/session.zig"), "formats")) @import("app/views/session.zig").formats else null,
},
.{
- .id = "spqGkQEUY37lw4mM50kKhibw0alHzv7g",
+ .id = "hZYjJ5xSrGCNsqU99TLFpLWjTmuVvuzU",
.name = "root_index",
.action = .index,
.view_name = "root",
@@ -165,7 +165,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/root.zig"), "formats")) @import("app/views/root.zig").formats else null,
},
.{
- .id = "MDW0dk8Pf9BQE3JrtBSDpzHHwH0LGJ7o",
+ .id = "hlY9sUEftxn1cFagCZ0YG2QWMzStZSHH",
.name = "redirect_index",
.action = .index,
.view_name = "redirect",
@@ -181,7 +181,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/redirect.zig"), "formats")) @import("app/views/redirect.zig").formats else null,
},
.{
- .id = "lqswc0Kw59ZgdA1CJACbL8WbSIr4rXRm",
+ .id = "bxMCdSzNla8dOrJIqIFnCGWvxx5J1rbt",
.name = "format_index",
.action = .index,
.view_name = "format",
@@ -197,7 +197,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/format.zig"), "formats")) @import("app/views/format.zig").formats else null,
},
.{
- .id = "ihQeHBf6BTYQykrGOnhjjByfs4wWdavM",
+ .id = "rIxNbXouG3ZpqHFO8RAhKuG4dfxrCmfU",
.name = "nested_route_example_index",
.action = .index,
.view_name = "nested/route/example",
@@ -213,7 +213,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/nested/route/example.zig"), "formats")) @import("app/views/nested/route/example.zig").formats else null,
},
.{
- .id = "AExhngOpBhhsRjyRKnOywrnJV2VfR65Z",
+ .id = "MDYdlPqfJvJHMzcioZUZdK2TOnx7i8t3",
.name = "mail_index",
.action = .index,
.view_name = "mail",
@@ -229,7 +229,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/mail.zig"), "formats")) @import("app/views/mail.zig").formats else null,
},
.{
- .id = "qefFQVtUvwXDp5JTXTNCc6utW4zcbosp",
+ .id = "JVZVGMPWkYQzwVvzU2GyNyliLXjmXp3c",
.name = "anti_csrf_index",
.action = .index,
.view_name = "anti_csrf",
@@ -245,7 +245,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/anti_csrf.zig"), "formats")) @import("app/views/anti_csrf.zig").formats else null,
},
.{
- .id = "qQtDJ8sV9vJYJmHEVPeNpzj2Qhmh2XMP",
+ .id = "WxnEz7xrSDSwdw95SwtH3p1pilaroxnr",
.name = "markdown_index",
.action = .index,
.view_name = "markdown",
@@ -261,7 +261,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/markdown.zig"), "formats")) @import("app/views/markdown.zig").formats else null,
},
.{
- .id = "UnNRfU7hM7J92xUMaPg20RtRJsDoXMXE",
+ .id = "LNFRaT4tqJrf1f11TJXyzmkfZtITVvqd",
.name = "init_index",
.action = .index,
.view_name = "init",
@@ -277,7 +277,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/init.zig"), "formats")) @import("app/views/init.zig").formats else null,
},
.{
- .id = "ZfrniROoeeuiKlk3gCgKfCr6WrDW0OY9",
+ .id = "xRO7XerJH97skZvolf7A6XoAUKW6NypE",
.name = "kvstore_index",
.action = .index,
.view_name = "kvstore",
@@ -293,7 +293,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/kvstore.zig"), "formats")) @import("app/views/kvstore.zig").formats else null,
},
.{
- .id = "yoonae7d0jc5bDqkypoVl3Q3EgSusMoC",
+ .id = "OZXcPZfi428ON34mmPs6rveiTyYZZk7r",
.name = "render_template_index",
.action = .index,
.view_name = "render_template",
@@ -309,7 +309,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/render_template.zig"), "formats")) @import("app/views/render_template.zig").formats else null,
},
.{
- .id = "yMqyoHvwyQa3l6VDK0PvzoTMsY754wk4",
+ .id = "PqEitHYDIGmhdGNJY1duijJ88GlmxC57",
.name = "cache_index",
.action = .index,
.view_name = "cache",
@@ -325,7 +325,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/cache.zig"), "formats")) @import("app/views/cache.zig").formats else null,
},
.{
- .id = "fnRX4YOb2aUS88rKQR40krb1xfp4JFG9",
+ .id = "PAmbq36hsUlpA9FE5wnq4KWQCFtRmXAm",
.name = "basic_index",
.action = .index,
.view_name = "basic",
@@ -341,7 +341,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/basic.zig"), "formats")) @import("app/views/basic.zig").formats else null,
},
.{
- .id = "PixHoG933QEkAPVs1DoxwVTovKglhUfN",
+ .id = "XvL4PkpzKXoVQEuOXvzixsov6HX6sQom",
.name = "errors_index",
.action = .index,
.view_name = "errors",
@@ -357,7 +357,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/errors.zig"), "formats")) @import("app/views/errors.zig").formats else null,
},
.{
- .id = "Efo0V2HYbMa5G8KQgx426eLdhdRdoBTe",
+ .id = "eUOCJMQ5ZoBwTp5pFJUFVr2laenWUlVn",
.name = "file_upload_index",
.action = .index,
.view_name = "file_upload",
@@ -373,7 +373,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/file_upload.zig"), "formats")) @import("app/views/file_upload.zig").formats else null,
},
.{
- .id = "UFcXVgtoOZX4i55aI7jd9LhQRuG34jPM",
+ .id = "vMS9iOity7uJCLa8HUv3WFKV2jW9RDzw",
.name = "quotes_post",
.action = .post,
.view_name = "quotes",
@@ -389,7 +389,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/quotes.zig"), "formats")) @import("app/views/quotes.zig").formats else null,
},
.{
- .id = "DLVKGAGIzETt2h0PFnKeFDkwpOAMLq93",
+ .id = "ZkOxo7cpVDX5J47H2e3EpDCDv41ki5In",
.name = "anti_csrf_post",
.action = .post,
.view_name = "anti_csrf",
@@ -405,7 +405,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/anti_csrf.zig"), "formats")) @import("app/views/anti_csrf.zig").formats else null,
},
.{
- .id = "mvyx5eMKF09eaoqExLqa0AXA8GdI1H1e",
+ .id = "ESA0VfqrKTR6AtD8x27ITjOQj16XoyJI",
.name = "session_post",
.action = .post,
.view_name = "session",
@@ -421,7 +421,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/session.zig"), "formats")) @import("app/views/session.zig").formats else null,
},
.{
- .id = "joZaA2JbO0heJCowS1cwcmrN91zWYgGB",
+ .id = "zmM4FLftB41eoVKtz9LGD5C4CCc0FrBS",
.name = "cache_post",
.action = .post,
.view_name = "cache",
@@ -437,7 +437,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/cache.zig"), "formats")) @import("app/views/cache.zig").formats else null,
},
.{
- .id = "BGRJZnQctDt9GY5dXkSDYgnveu5ePT66",
+ .id = "pXsvArTaNZrKNdoBOrl0FeL4LuwSVCCl",
.name = "params_post",
.action = .post,
.view_name = "params",
@@ -453,7 +453,7 @@ pub const routes = [_]jetzig.Route{
.formats = if (@hasDecl(@import("app/views/params.zig"), "formats")) @import("app/views/params.zig").formats else null,
},
.{
- .id = "atwIYYFWAXOVXAszR1d794p3O2aUM3b4",
+ .id = "pHqpr0GKxaiBP8VIpO8TJx0DQHIkulnX",
.name = "file_upload_post",
.action = .post,
.view_name = "file_upload",
diff --git a/src/jetzig.zig b/src/jetzig.zig
index 01a8439..db5a2c1 100644
--- a/src/jetzig.zig
+++ b/src/jetzig.zig
@@ -25,7 +25,6 @@ pub const auth = @import("jetzig/auth.zig");
pub const callbacks = @import("jetzig/callbacks.zig");
pub const debug = @import("jetzig/debug.zig");
pub const TemplateContext = @import("jetzig/TemplateContext.zig");
-pub const Channels = @import("jetzig/Channels.zig");
pub const DateTime = jetcommon.types.DateTime;
pub const Time = jetcommon.types.Time;
diff --git a/src/jetzig/App.zig b/src/jetzig/App.zig
index 5f9d7cc..268aafb 100644
--- a/src/jetzig/App.zig
+++ b/src/jetzig/App.zig
@@ -34,7 +34,7 @@ pub fn start(self: *const App, routes_module: type, options: AppOptions) !void {
defer mime_map.deinit();
try mime_map.build();
- const routes = try createRoutes(self.allocator, &routes_module.routes);
+ const routes = try createRoutes(self.allocator, if (@hasDecl(routes_module, "routes")) &routes_module.routes else &.{});
defer {
for (routes) |var_route| {
var_route.deinitParams();
@@ -86,8 +86,8 @@ pub fn start(self: *const App, routes_module: type, options: AppOptions) !void {
self.env,
routes,
self.custom_routes.items,
- &routes_module.jobs,
- &routes_module.mailers,
+ if (@hasDecl(routes_module, "jobs")) &routes_module.jobs else &.{},
+ if (@hasDecl(routes_module, "jobs")) &routes_module.mailers else &.{},
&mime_map,
&store,
&job_queue,
@@ -106,8 +106,8 @@ pub fn start(self: *const App, routes_module: type, options: AppOptions) !void {
.vars = self.env.vars,
.environment = self.env.environment,
.routes = routes,
- .jobs = &routes_module.jobs,
- .mailers = &routes_module.mailers,
+ .jobs = if (@hasDecl(routes_module, "jobs")) &routes_module.jobs else &.{},
+ .mailers = if (@hasDecl(routes_module, "jobs")) &routes_module.mailers else &.{},
.store = &store,
.cache = &cache,
.repo = &repo,
diff --git a/src/jetzig/Channels.zig b/src/jetzig/Channels.zig
deleted file mode 100644
index 521ad5b..0000000
--- a/src/jetzig/Channels.zig
+++ /dev/null
@@ -1,34 +0,0 @@
-const std = @import("std");
-
-const Channels = @This();
-
-pub const Channel = struct {
- name: []const u8,
-
- pub fn deliver(self: Channel, message: []const u8) !void {
- _ = self;
- std.debug.print("message: {s}\n", .{message});
- }
-};
-
-allocator: std.mem.Allocator,
-channels: std.StringHashMap(Channel),
-
-pub fn init(allocator: std.mem.Allocator) Channels {
- return .{
- .allocator = allocator,
- .channels = std.StringHashMap(Channel).init(allocator),
- };
-}
-
-pub fn acquire(self: *Channels, name: []const u8) !Channel {
- const channel = Channel{ .name = name };
- try self.channels.put(name, channel);
-}
-
-pub fn broadcast(self: Channels, message: []const u8) !void {
- var it = self.channels.iterator();
- while (it.next()) |entry| {
- try entry.value_ptr.deliver(message);
- }
-}
diff --git a/src/jetzig/http.zig b/src/jetzig/http.zig
index 1ca438e..5137903 100644
--- a/src/jetzig/http.zig
+++ b/src/jetzig/http.zig
@@ -10,7 +10,6 @@ pub const StaticRequest = if (build_options.environment == .development)
else
@import("http/StaticRequest.zig");
pub const Response = @import("http/Response.zig");
-pub const WebsocketClient = @import("http/WebsocketClient.zig");
pub const Session = @import("http/Session.zig");
pub const Cookies = @import("http/Cookies.zig");
pub const Headers = @import("http/Headers.zig");
diff --git a/src/jetzig/http/Server.zig b/src/jetzig/http/Server.zig
index 31cc152..9fd9ce1 100644
--- a/src/jetzig/http/Server.zig
+++ b/src/jetzig/http/Server.zig
@@ -22,8 +22,6 @@ repo: *jetzig.database.Repo,
global: *anyopaque,
decoded_static_route_params: []const *jetzig.data.Value = &.{},
debug_mutex: std.Thread.Mutex = .{},
-websocket_client: jetzig.http.WebsocketClient = undefined,
-channels: jetzig.Channels,
const Server = @This();
@@ -54,7 +52,6 @@ pub fn init(
.job_queue = job_queue,
.cache = cache,
.repo = repo,
- .channels = jetzig.Channels.init(allocator),
.global = global,
};
}
@@ -111,11 +108,6 @@ pub fn listen(self: *Server) !void {
thread_count,
});
- var client = try jetzig.http.WebsocketClient.init(self.allocator, .{});
- try client.handshake();
- self.websocket_client = client;
- defer client.deinit();
-
self.initialized = true;
try jetzig.http.middleware.afterLaunch(self);
diff --git a/src/jetzig/http/WebsocketClient.zig b/src/jetzig/http/WebsocketClient.zig
deleted file mode 100644
index 632c08b..0000000
--- a/src/jetzig/http/WebsocketClient.zig
+++ /dev/null
@@ -1,38 +0,0 @@
-const std = @import("std");
-
-const httpz = @import("httpz");
-const jetzig = @import("../../jetzig.zig");
-
-allocator: std.mem.Allocator,
-websocket_client: *httpz.websocket.Client,
-
-const WebsocketClient = @This();
-
-pub fn init(allocator: std.mem.Allocator, options: struct {}) !WebsocketClient {
- _ = options;
- const client = try allocator.create(httpz.websocket.Client);
- client.* = try httpz.websocket.Client.init(allocator, .{
- .port = 9224,
- .host = "localhost",
- });
-
- return .{
- .allocator = allocator,
- .websocket_client = client,
- };
-}
-
-pub fn deinit(self: WebsocketClient) void {
- self.websocket_client.deinit();
-}
-
-pub fn handshake(self: WebsocketClient) !void {
- try self.websocket_client.handshake("/ws", .{
- .timeout_ms = 1000,
- .headers = "Host: localhost:9224", // TODO: Auth header ?
- });
-}
-
-pub fn broadcast(self: WebsocketClient, message: []const u8) !void {
- try self.websocket_client.write(@constCast(message));
-}
diff --git a/src/jetzig/middleware.zig b/src/jetzig/middleware.zig
index b87f3e2..4be3640 100644
--- a/src/jetzig/middleware.zig
+++ b/src/jetzig/middleware.zig
@@ -5,7 +5,6 @@ pub const HtmxMiddleware = @import("middleware/HtmxMiddleware.zig");
pub const CompressionMiddleware = @import("middleware/CompressionMiddleware.zig");
pub const AuthMiddleware = @import("middleware/AuthMiddleware.zig");
pub const AntiCsrfMiddleware = @import("middleware/AntiCsrfMiddleware.zig");
-pub const HotReloadMiddleware = @import("middleware/HotReloadMiddleware.zig");
const RouteOptions = struct {
content: ?[]const u8 = null,
diff --git a/src/jetzig/middleware/HotReloadMiddleware.zig b/src/jetzig/middleware/HotReloadMiddleware.zig
deleted file mode 100644
index 85f5000..0000000
--- a/src/jetzig/middleware/HotReloadMiddleware.zig
+++ /dev/null
@@ -1,16 +0,0 @@
-const std = @import("std");
-const jetzig = @import("../../jetzig.zig");
-
-pub const middleware_name = "hot_reload";
-
-const HotReloadMiddleware = @This();
-
-pub fn afterRequest(request: *jetzig.http.Request) !void {
- var session = try request.session();
- try session.put("_jetzig_hot_reload", "test");
-}
-
-pub fn afterLaunch(server: *jetzig.http.Server) !void {
- try server.logger.INFO("LAUNCH", .{});
- try server.channels.broadcast("jetzig-reload");
-}
diff --git a/websockets/main.zig b/websockets/main.zig
deleted file mode 100644
index f5585d1..0000000
--- a/websockets/main.zig
+++ /dev/null
@@ -1,74 +0,0 @@
-const std = @import("std");
-const websocket = @import("httpz").websocket;
-
-pub fn main() !void {
- var gpa = std.heap.GeneralPurposeAllocator(.{}){};
- const allocator = gpa.allocator();
-
- var server = try Server.init(allocator);
- defer server.deinit();
-
- try server.listen();
-}
-
-const Server = struct {
- allocator: std.mem.Allocator,
- websocket_server: websocket.Server(Handler),
- sessions: std.ArrayList(Stream),
-
- const Stream = struct {
- key: []const u8,
- connection: *websocket.Conn,
- };
-
- pub const App = struct {
- streams: std.ArrayList(Stream),
- };
-
- pub fn init(allocator: std.mem.Allocator) !Server {
- return .{
- .allocator = allocator,
- .websocket_server = try websocket.Server(Handler).init(allocator, .{
- .port = 9224,
- .address = "127.0.0.1",
- .handshake = .{
- .timeout = 3,
- .max_size = 1024,
- .max_headers = 0,
- },
- }),
- .sessions = std.ArrayList(Stream).init(allocator),
- };
- }
-
- pub fn deinit(self: *Server) void {
- self.websocket_server.deinit();
- self.sessions.deinit();
- }
-
- pub fn listen(self: *Server) !void {
- var app: App = .{ .streams = std.ArrayList(Stream).init(self.allocator) };
- try self.websocket_server.listen(&app);
- }
-};
-
-const Handler = struct {
- app: *Server.App,
- connection: *websocket.Conn,
-
- pub fn init(handshake: websocket.Handshake, connection: *websocket.Conn, app: *Server.App) !Handler {
- std.debug.print("handshake: {any}\n", .{handshake});
- try app.streams.append(.{ .key = handshake.key, .connection = connection });
-
- return .{
- .app = app,
- .connection = connection,
- };
- }
-
- // You must defined a public clientMessage method
- pub fn clientMessage(self: *Handler, data: []const u8) !void {
- std.debug.print("message: {s}\n", .{data});
- try self.connection.write(data); // echo the message back
- }
-};