426 Commits

Author SHA1 Message Date
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
Bob Farrell
be85c13369 Provide interface for adding response headers 2024-02-25 14:20:22 +00:00
Bob Farrell
a07c71e725 Refactor response interface
Create `jetzig.http.Response` when `std.http.Server.Response` is created
and delegate all management of `std.http.Server.Response` to
`jetzig.http.Response`. Using this internally means we use the same
internal interface for the `Response` as the user, which gives us things
like response headers management in views for free (user simply calls
`request.response.headers.append()` etc.).
2024-02-25 10:32:34 +00:00
bobf
2ebb644421
Merge pull request #8 from jetzig-framework/json-and-query-param-parsing
JSON and query param parsing/SSG params
2024-02-25 09:29:01 +00:00
Bob Farrell
216b86c235 JSON and query param parsing/SSG params
Implement `jetzig.http.Request.params()` which parses either a JSON
request body or a query param string into a `jetzig.data.Value`.

Allow configuring params for static site generation - configure an array
of params for each endpoint which is then parsed at build time and a
separate JSON and HTML output is generated for each by invoking the
relevant view function and passing in resource ID/params. Params are
stored in generated `routes.zig` for route matching at run time.
2024-02-25 09:25:00 +00:00
Bob Farrell
280f1eaadd Update to latest Zmpl version
Fix a few bits of breakage with build - Jetzig does not have an
executable, use `demo/` which links to local Jetzig to test features.
2024-02-18 18:42:46 +00:00
Bob Farrell
8c5ffcb9f6 Fix logo path 2024-02-17 16:02:52 +00:00
Bob Farrell
66f6e13741 Update README
Update checklist/contributors
2024-02-17 15:58:33 +00:00
bobf
a1933b6164
Merge pull request #5 from jetzig-framework/static-routes
Static routes
2024-02-17 15:46:38 +00:00
Bob Farrell
d52aed8a9b PR feedback
Remove `anyerror` from example definitions - we only need this in the
struct definition, no need to have explicit error set defined in
user-defined view functions.
2024-02-17 15:35:40 +00:00
Bob Farrell
8ac2afbec2 PR feedback. 2024-02-17 15:31:40 +00:00
Bob Farrell
31927cdb6b Static routes
Generate views defined with `request: *jetzig.http.StaticRequest` as
static content into `static/` directory so that exported JSON and HTML
can be rendered direct from disk, skipping runtime rendering.
2024-02-17 15:28:27 +00:00
Bob Farrell
6d487392a8 Add z1fire to contributors
Discord admin and public relations officer. :)
2024-02-15 22:41:18 +00:00
Bob Farrell
bdb813c521 Dump stack trace on internal server error
Provide stack trace for debugging runtime errors in debug builds
2024-02-15 21:40:21 +00:00
Bob Farrell
7958480ff7 Provide abstraction for headers
Basic abstraction wrapping existing std.http.Headers to provide a stable
interface.
2024-02-15 20:01:07 +00:00
bobf
3ba070a72a
Merge pull request #4 from Deecellar/fix
Server fix for middleware
2024-02-09 22:53:30 +00:00
rimuspp
ba52d32582 Fixing the template 2024-02-09 00:30:13 +00:00
rimuspp
0395d00b4b
Server fix for middleware 2024-02-08 19:09:54 -05:00