443 Commits

Author SHA1 Message Date
bobf
9300c68ee2
Merge pull request #27 from jetzig-framework/remove-unneeded-filesystem-lookup
Remove unneeded filesystem lookup
2024-03-17 11:04:44 +00:00
Bob Farrell
bc64f58c44 Remove unneeded filesystem lookup
`root_path` is cruft from previous route/template matching mechanism.
Caused failure when running binary in isolation: binary can now run
independently without any dependency on file system other than:

```
* public/ <-- should always be separate to allow e.g. serving directly
              via nginx
* static/ <-- later will be compiled into binary
```
2024-03-17 10:37:18 +00:00
bobf
0bd26cd759
Merge pull request #26 from jetzig-framework/fix-Headers.getFirstValue
Fix Headers.getFirstValue
2024-03-17 10:36:56 +00:00
Bob Farrell
3c47dff96e Fix Headers.getFirstValue
Bugfix to resolve issue with undefined behaviour when calling
`getFirstValue` - first header would always be returned. Add regression
test.
2024-03-17 10:26:10 +00:00
bobf
b61700cff6
Merge pull request #25 from jetzig-framework/zmpl-partial-args
Update Zmpl, provides partial args (with type inference)
2024-03-16 21:18:56 +00:00
Bob Farrell
9664cf8e80 Update Zmpl, provides partial args (with type inference) 2024-03-16 21:13:06 +00:00
Bob Farrell
b4937d34a1 Add tokamak to related projects 2024-03-16 09:49:36 +00:00
bobf
fe7f0a4137
Merge pull request #24 from jetzig-framework/cli-server-windows
Fix Windows "jetzig server" command
2024-03-14 20:39:33 +00:00
Bob Farrell
304c2cba42 Fix Windows "jetzig server" command 2024-03-14 20:32:43 +00:00
bobf
df97210586
Merge pull request #23 from jetzig-framework/layouts
Implement layouts
2024-03-14 19:50:02 +00:00
Bob Farrell
aa036fde8b Implement layouts
Latest Zmpl provides `template.renderWithLayout(other_template, data)`,
allowing a template to be renedered within another template.

Create layouts in `src/app/views/layouts/` or use
`jetzig generate layout [name]` and set `pub const layout = "name";` in
each view file.
2024-03-11 22:36:18 +00:00
bobf
9be2032e65
Merge pull request #22 from jetzig-framework/cli-server
Implement `jetzig server` command
2024-03-11 18:44:44 +00:00
Bob Farrell
e980782316 Implement jetzig server command
Runs a development server and auto-reloads when changes are detected to
files.

Note that a "change" is just an mtime update, Zig does a more
intelligent change detection so avoids unnecessary recompiles, so the
server reloads very quickly.
2024-03-11 18:38:48 +00:00
bobf
4d7bd71324
Merge pull request #21 from jetzig-framework/fix-routes-windows-paths
Fix Windows paths again
2024-03-10 17:19:49 +00:00
Bob Farrell
5ff4d7127d Fix Windows paths again
Previous fix did not work, `@import` expects forward slashes so escaping
backslashes doesn't help. Replace `\` with `/` instead.
2024-03-10 17:13:17 +00:00
bobf
0713062f74
Merge pull request #20 from jetzig-framework/fix-routes-windows-paths
Fix routes.zig Windows paths
2024-03-10 17:02:56 +00:00
Bob Farrell
e004eb3d86 Fix routes.zig Windows paths
Use `std.zig.pstringEscape` to correctly escape a string for setting as
a Zig string. This should catch any potential issue with escaping
strings.
2024-03-10 17:01:41 +00:00
bobf
4010383ff7
Merge pull request #19 from jetzig-framework/view-imports
Allow importing .zig files from src/ in views
2024-03-10 15:16:40 +00:00
Bob Farrell
a78d53a19a Allow importing .zig files from src/ in views
Views are copied to zig-cache, meaning that any files in `src/` are not
available for `@import` by default. Copy all .zig files from `src/` into
zig-cache so that relative imports work as expected. This also removes
the need to specifically copy views into zig-cache as the full tree is
now present.

Also fix a bug in static route fallback - remove superfluous underscore
so static routes with non-matching params render default HTML/JSON
content.
2024-03-10 14:10:53 +00:00
bobf
edbf433a81
Merge pull request #18 from jetzig-framework/format-from-content-type
Use content-type header if present to detect format
2024-03-10 11:39:55 +00:00
Bob Farrell
dd54d55423 Use content-type header if present to detect format
Detect request format (HTML or JSON) from `content-type` header.

Previous:
- path extension (.json, .html)
- "Accept" header
- default (.UNKNOWN => .HTML)

Current:
- path extension (.json, .html)
- "Accept" header
- "Content-Type" header
- default (.UNKNOWN => .HTML)

Adjust `http.Headers` to do case-insensitive matching to conform to HTTP
spec: https://www.rfc-editor.org/rfc/rfc9110.html#name-field-names
2024-03-10 11:31:39 +00:00
bobf
ea1962fcb8
Merge pull request #16 from jetzig-framework/cli-update
Add update command to CLI tool
2024-03-10 10:49:36 +00:00
bobf
670fe23cc8
Merge pull request #17 from jetzig-framework/streamline-project-build.zig
Streamline project build.zig
2024-03-10 10:14:21 +00:00
Bob Farrell
97d66aa6be Streamline project build.zig
Offload as much work as possible into new `jetzigInit` function provided
by Jetzig's `build.zig`. This means that a new Jetzig project's
`build.zig` is now almost completely vanilla with the exception of two
extra lines:

```zig
const jetzig = @import("jetzig");
```

```zig
    try jetzig.jetzigInit(b, exe, .{});
```
2024-03-10 10:06:36 +00:00
Bob Farrell
bec5f9c905 Add update command to CLI tool
Automatically update to latest version of Jetzig with `jetzig update`.
2024-03-09 19:45:59 +00:00
rimuspp
2a25084de6
Merge pull request #15 from jetzig-framework/CI-pr-skip
Not running on pull requests
2024-03-09 14:14:13 -05:00
rimuspp
fe37f51494
Not running on pull requests
We could, but that's wasteful
2024-03-09 14:08:02 -05:00
bobf
647833ca5a
Merge pull request #14 from jetzig-framework/cli-generate
CLI generate command
2024-03-09 19:07:45 +00:00
Bob Farrell
804bfb54ed Run CI workflow on PR to main 2024-03-09 18:54:23 +00:00
Bob Farrell
f954439489 CLI generate command
Provide `jetzig generate ...` commands for views, middleware, and
partials.
2024-03-09 18:47:08 +00:00
Bob Farrell
26cbe2b67c Swap out importing jetzig.zig for explicit files containing tests
Latest Zig nightly now hits a panic, probably we have a cyclic reference
in the tree. We should fix this ASAP otherwise we risk adding tests
without running them, but for now this should get builds passing again
with latest Zig.
2024-03-09 14:33:54 +00:00
Bob Farrell
d5a8f247d7 Fix HTML bug in project init source template
Typo - remove unwanted closing div tag. Tag is a multi-line block,
resulting in a superfluous `</div>` and generating incoherent HTML.
2024-03-09 13:03:57 +00:00
Bob Farrell
7e804c6935 Update Zmpl, fix issue with non-linebreak-terminated templates
Latest update normalizes input by adding a terminating linebreak to end
of input stream if not already present, fixing an issue where parsing
finalised with content still present in the char buf. A warning is also
raised requesting a bug report if this occurs.
2024-03-09 12:34:13 +00:00
Bob Farrell
3a91bbea48 Skip parsing functions that are not in Route.Action enum
Allow custom functions with arbitrary signatures and avoid any issues of
trying to parse functions that are not Jeztig route action functions
(i.e. index, get, post, put, patch, delete).
2024-03-09 11:43:44 +00:00
Bob Farrell
de40af0dc6 Fix init on Windows, update Zmpl for Windows module path fix 2024-03-07 18:41:09 +00:00
rimuspp
499bc69e64
Merge pull request #13 from jetzig-framework/Create-CI-for-the-cli-tooling
We now have CLI CI =D
2024-03-06 18:33:58 -05:00
rimuspp
c71886a574
We now have CLI CI =D 2024-03-06 18:33:47 -05:00
rimuspp
63f8236521
Update CI.yml 2024-03-06 18:29:17 -05:00
rimuspp
c08fe7c1e9
Update CI.yml 2024-03-06 18:23:09 -05:00
rimuspp
f165ffe73f
Update CI.yml 2024-03-06 18:16:50 -05:00
bobf
d37007f975
Merge pull request #12 from jetzig-framework/jetzig-init
Implement init command, get rid of old init script/artifacts
2024-03-06 23:01:05 +00:00
Bob Farrell
d3a3582136 Implement init command, get rid of old init script/artifacts
Remove old bash script for setting up a new project, do everything in
Zig to make it platform agnostic and give us an easy place to add
scaffolding commands in future.
2024-03-06 22:57:11 +00:00
rimuspp
01ac93ce81
Remove cache on builds
We are constantly getting master, this is not a good idea haha
2024-03-03 09:26:21 -05:00
rimuspp
51ed1f43f7
Merge pull request #11 from jetzig-framework/Setup-CI
Create CI
2024-03-03 09:21:00 -05:00
rimuspp
ba68afcc43
Create CI.yml
Welcome to jetzig nightly
2024-03-03 09:14:31 -05:00
Bob Farrell
29f4771264 Upgrade Zmpl (latest version provides partials), fix mime map memory leak 2024-03-03 14:12:35 +00:00
Bob Farrell
ce93abcd65 Simplify headers assignment, fix tests 2024-03-02 12:11:22 +00:00
bobf
cc39608d46
Merge pull request #10 from jetzig-framework/zig-std-http-overhaul
std.http overhaul
2024-03-02 11:32:30 +00:00
Bob Farrell
6ea210259d std.http overhaul
Andrew overhauled std.http to avoid allocations and put control of
connection + stream into hands of users. For now, do a barebones
implementation to restore compatibility, later we can do keepalive and
pipelining. For now, still getting decent enough performance the "slow"
way.

Relevant commit: 6395ba852a

Commit message copied here for posterity:

> Author: Andrew Kelley <andrew@ziglang.org>
> Date:   Tue Feb 20 03:30:51 2024 -0700
> std.http.Server: rework the API entirely
> Mainly, this removes the poorly named `wait`, `send`, `finish`
> functions, which all operated on the same "Response" object, which was
> actually being used as the request.
>
> Now, it looks like this:
> 1. std.net.Server.accept() gives you a std.net.Server.Connection
> 2. std.http.Server.init() with the connection
> 3. Server.receiveHead() gives you a Request
> 4. Request.reader() gives you a body reader
> 5. Request.respond() is a one-shot, or Request.respondStreaming() creates
>    a Response
> 6. Response.writer() gives you a body writer
> 7. Response.end() finishes the response; Response.endChunked() allows
>    passing response trailers.
>
> In other words, the type system now guides the API user down the correct
> path.
>
> receiveHead allows extra bytes to be read into the read buffer, and then
> will reuse those bytes for the body or the next request upon connection
> reuse.
>
> respond(), the one-shot function, will send the entire response in one
> syscall.
>
> Streaming response bodies no longer wastefully wraps every call to write
> with a chunk header and trailer; instead it only sends the HTTP chunk
> wrapper when flushing. This means the user can still control when it
> happens but it also does not add unnecessary chunks.
>
> Empirically, in my example project that uses this API, the usage code is
> significantly less noisy, it has less error handling while handling
> errors more correctly, it's more obvious what is happening, and it is
> syscall-optimal.
>
> Additionally:
> * Uncouple std.http.HeadParser from protocol.zig
> * Delete std.Server.Connection; use std.net.Server.Connection instead.
>   - The API user supplies the read buffer when initializing the
>     http.Server, and it is used for the HTTP head as well as a buffer
>     for reading the body into.
> * Replace and document the State enum. No longer is there both "start"
>   and "first".
2024-03-01 22:47:11 +00:00
Bob Farrell
d855b9f703 Implement MIME type inference
When serving content from `public/`, use MIME type lookup to provide an
appropriate content-type header.

MIME types borrowed from:

  https://mimetype.io/all-types
  https://github.com/patrickmccallum/mimetype-io/blob/master/src/mimeData.json
2024-02-26 22:38:43 +00:00