96 Commits

Author SHA1 Message Date
Bob Farrell
2dd4a19e2e Public routing path
Set `public_routing_path` config option to specify a request path prefix
for public requests.
2025-05-05 10:31:02 +01:00
Bob Farrell
368f3f4ca5 Implement request.renderText()
Render a text string (+ status code) directly.
2025-05-05 10:06:29 +01:00
TheJltres
1acb6f5df9
Reset config to default 2025-05-03 11:04:29 +02:00
TheJltres
de48478c6d
Remove comand, not needed 2025-05-03 00:00:13 +02:00
TheJltres
6f0e731303
Testing seeders 2025-05-01 22:23:39 +02:00
U-Zyn Chua
4c568f2606
Minor typo fix 2025-04-16 15:59:45 +08:00
Bob Farrell
c26d563898 Zig 0.15 compatibility
Various dependencies updated after changes to `std.zig.Ast` and
`std.LinkedList` and other things.
2025-04-09 20:08:38 +01:00
Bob Farrell
2cb1b4e959 Adjust test, fix memory leak in hashPassword, deinit repo on test app deinit 2025-03-23 13:28:09 +00:00
Sean M. Collins
79574ed861 Use defer to free hashed_pass 2025-03-20 13:54:13 -04:00
Sean M. Collins
aae890998f fix spelling mistake 2025-03-10 22:07:12 -04:00
Sean M. Collins
21bf237437 Shrink database.zig and comment 2025-03-10 21:57:02 -04:00
Sean M. Collins
9e4e8529c5 Create a template file for init
This allows us to use database.zig for CI, while still creating a blank
database.zig for new projects that are created via jetzig init
2025-03-10 21:49:36 -04:00
Sean M. Collins
70a8b0f698 Add tests for login view 2025-03-10 21:20:33 -04:00
Sean M. Collins
22688ccaa3 Set adapter to postgresql 2025-03-10 17:13:08 -04:00
Sean M. Collins
f3788567bb Fix argument to first migration 2025-03-10 17:05:09 -04:00
Sean M. Collins
58f7e0e76a Add User to schema 2025-03-10 16:50:11 -04:00
Sean M. Collins
b070d281e3 Add user table 2025-03-10 16:32:27 -04:00
Sean M. Collins
9012ec3aaf Add an example for using auth for logging in 2025-03-10 16:26:58 -04:00
Sean M. Collins
d8a992ce38 Set same_site to correct type
Fixes #170
2025-03-08 07:52:02 -05:00
Bob Farrell
06674db51f Use fork of zig-args (temporary)
Revert when [this PR](https://github.com/ikskuh/zig-args/pull/67) is
merged.
2025-03-02 13:12:29 +00:00
Bob Farrell
099a2a5349 Use Zig compiler
Default to not using LLVM for application compilation. This gives more
than 2x performance improvement for compilation stage.
2025-03-01 14:33:17 +00:00
Bob Farrell
c0d6fb162b Latest Zig build.zig.zon format compatibility 2025-03-01 12:28:08 +00:00
Bob Farrell
a5430ff380 Zig 0.14 test runner config changes
Update dependencies to match new Zig build config API for test runners,
misc. fixes needed after upgrading dependencies.
2025-02-02 11:31:40 +00:00
Bob Farrell
35adaf3009 Valkey backend for JetKV 2024-12-06 21:31:02 +00:00
Bob Farrell
f44a6b33c5 Routing updates
Implement `/foo/1/edit` route/view.

Allow setting HTTP verb by passing e.g. `/_PATCH` as the last segment of
a URL - this allows browsers to submit a `POST` request with a
pseudo-HTTP verb encoded in the URL which Jetzig can translate, i.e.
allowing forms to submit a `PATCH`.
2024-11-24 20:46:56 +00:00
Bob Farrell
1565ae3b73 Debug console
Use `jetzig server` or `zig build -Ddebug_console=true run` to launch a
development server with the debug console enabled.

When an error is encountered a formatted stack trace is dumped to the
browser along with the current response data. Both outputs are
syntax-highlighted using Prism JS.
2024-11-23 18:07:19 +00:00
Bob Farrell
8095bbcb76 Implement request.renderTemplate
Clean up request state.
2024-11-23 13:42:14 +00:00
Bob Farrell
036aec1682 Misc. tidying 2024-11-23 13:14:11 +00:00
Bob Farrell
6e6f1bec1b Closes #108: Anti-CSRF middleware
Add to middleware in app's `src/main.zig`:

```zig
pub const jetzig_options = struct {
    pub const middleware: []const type = &.{
        jetzig.middleware.AntiCsrfMiddleware,
    };
};
```

CSRF token available in Zmpl templates:

```
{{context.authenticityToken()}}
```
or render a hidden form element:
```
{{context.authenticityFormElement()}}
```

The following HTML requests are rejected (403 Forbidden) if the
submitted query param does not match the value stored in the encrypted
session (added automatically when the token is generated for a template
value):

* POST
* PUT
* PATCH
* DELETE

JSON requests are not impacted - users should either disable JSON
endpoints or implement a different authentication method to protect
them.
2024-11-23 12:49:49 +00:00
Bob Farrell
92dce21244 Database CLI improvements
Eradication of `data` arg to requests. We no longer need to pass this
value around as we have a) type inference, b) nested object insertion
via `put` and `append`.

Fix `joinPath` numeric type coercion

Detect empty string params and treat them as blank with expectParams()

Fix error logging/stack trace printing.

Update Zmpl - includes debug tokens + error tracing to source template
in debug builds.
2024-11-19 21:39:01 +00:00
Bob Farrell
b95506caf9 Params helpers
Implement `request.expectParams()` to coerce params to a given struct.
`request.paramsInfo()` provides information about each param (present,
blank, failed + original values and errors where applicable).
2024-11-17 19:07:27 +00:00
Bob Farrell
e3ab49fa5a Refactor Route
Move all route types into a single union and remove leftover junk.

Deprecate view functions that receive a `*jetzig.Data` argument (we will
stay backward-compatible until we have a valid reason to drop support
for legacy view functions - the extra code overhead is pretty minimal).
2024-11-17 15:08:54 +00:00
Bob Farrell
a6d1b92f5e Simplify DevelopmentLogger, add ProductionLogger
Add auth helper to create a user from CLI:

```
jetzig auth user:create user@example.com
```
2024-11-11 22:25:35 +00:00
Bob Farrell
b0613aab10 Import Schema in demo/init config 2024-11-09 18:36:48 +00:00
Bob Farrell
78a9ccaaa4 Fix database config path 2024-11-09 18:06:16 +00:00
Bob Farrell
d27907a1c5 WIP 2024-11-09 17:13:32 +00:00
Bob Farrell
1c2cbaca77 WIP 2024-11-09 17:12:49 +00:00
Bob Farrell
c7b79f144a Fixes for https://github.com/ziglang/zig/pull/21817 2024-11-06 08:44:07 +00:00
IbrahimOuhamou
bd2761b12f added session.remove to demo thanks to Allah 2024-11-03 13:10:47 +01:00
Bob Farrell
f971f18a60 Global data
Define `pub const Global = SomeType` at top level in `src/main.zig`,
then create a pointer to `SomeType` and pass to `app.start`:

```
app.start(routes, .{ .global = global });
```

Then access in a view as `request.global`.
2024-10-28 09:07:06 +00:00
Bob Farrell
9e4a81aa19 Closes #105: Configure SMTP from environment variables
Fall back to hardcoded values if each `JETZIG_SMTP_*` variable is not
present.
2024-10-17 22:09:04 +01:00
Bob Farrell
e98c5ec3df Update http.zig
Refactor routes generation to standalone exe (fixes some build-time vs.
run-time issues).
2024-08-24 11:18:08 +01:00
Bob Farrell
1406447f24 Implement response format constraints
Define `pub const formats` in a view to specify which formats are
available. Use this to e.g. disable JSON responses.
2024-08-04 16:06:39 +01:00
Bob Farrell
9971cde875 Close #89: Implement file upload support
Use `request.file("form-field-name")` to try to find a multipart-encoded
form value for the given name. Returns `jetzig.http.File` if a match is
found which provides `content` (uploaded file content) and `filename`
(filename as passed by browser).
2024-06-19 20:47:05 +01:00
Bob Farrell
179b5e77c3 Comment custom route - use as example only 2024-06-09 11:18:14 +01:00
Bob Farrell
3882eba2f3 Clean up static params and init script 2024-06-09 11:13:33 +01:00
Bob Farrell
e30d340a7a Embed static routes in compiled exe
Remove need for static routes output files to be copied/generated in
deployment.
2024-06-08 19:37:41 +01:00
Bob Farrell
2d921a1c27 Add jetzig routes command
Output all current routes. Invokes `zig build jetzig:routes`.
2024-06-05 21:26:23 +01:00
Bob Farrell
06e13b3752 Add missing (accidentally .gitignored) templates 2024-06-03 22:15:31 +01:00
Bob Farrell
a46bc0ed19 Test helpers
Add `jetzig test` command which runs build step `jetzig:test`.

Add `jetzig.testing` namespace which provides test helpers and a test
app.

Add tests to view generator (i.e. include tests for generated routes).
2024-06-03 21:56:32 +01:00