mirror of
https://github.com/jetzig-framework/jetzig.git
synced 2025-05-14 14:06:08 +00:00
WIP
This commit is contained in:
parent
36f9d32ae6
commit
136aed3d54
14
build.zig
14
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,
|
||||
|
@ -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 = .{
|
||||
|
@ -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,
|
||||
|
1
demo/.gitignore
vendored
1
demo/.gitignore
vendored
@ -4,3 +4,4 @@ static/
|
||||
src/app/views/**/.*.zig
|
||||
.DS_Store
|
||||
log/
|
||||
src/routes.zig
|
||||
|
@ -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);
|
||||
}
|
@ -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);
|
||||
|
@ -1,11 +1,11 @@
|
||||
<div class="text-center pt-10 m-auto">
|
||||
<h1>HELLO</h1>
|
||||
<h1>SPEED</h1>
|
||||
<h1>SPEED</h1>
|
||||
<h1>SPEED</h1>
|
||||
<h1>SPEED</h1>
|
||||
<h1>SPEED</h1>
|
||||
<h1>SPEED</h1>
|
||||
<h1>HI THERE</h1>
|
||||
<h1>BOOP</h1>
|
||||
<h1>BLAP</h1>
|
||||
<h1>BLAPPPPP</h1>
|
||||
<h1>CAHCHACA</h1>
|
||||
<h1>YAY</h1>
|
||||
<h1>SPEED</h1>
|
||||
<h1>SPEED</h1>
|
||||
<h1>SPEED</h1>
|
||||
|
@ -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"),
|
||||
};
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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");
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
}
|
@ -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,
|
||||
|
@ -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");
|
||||
}
|
@ -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
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user