This is a follow-up fix to https://github.com/denoland/fresh/pull/2792
The original fix skipped over route groups which lead to them being
mixed with non-grouped routes. This in turn confused the middleware
processing part when building the final routes.
I noticed a small bug with the default GET handlers where middlewares
were not being run. This pull requests fixes the bug and adds some unit
tests for this behavior.
This PR fixes an issue in the route sorting logic when comparing a route
segment with a group vs a segment without one.
- `/(app)/[org]/[app]/index.ts`
- `/auth/login.ts`
When determing the order of these two routes we need to skip over the
`(app)` group to the next non-group segment. This ensures that we are
only scoring actual segments with each other and non-existing ones.
This commit fixes a bug where negative numbers were not correctly
serialized, because the value parser confused "references" (which is
where special negative tokens for special values exist), and "values"
(where negative numbers are just negative numbers). The parser now
correctly distinguishes between the two.
This commit adds some useful automatic instrumentation for when users
are using `--unstable-otel`:
- Fresh renames the span for incoming HTTP requests to `$METHOD $ROUTE`
and the `http.route` attribute is added.
- Fresh creates a span around FS route handlers, showing whether they
returned a response or data.
- Fresh creates a span around async components, showing how long they
took to execute.
- Fresh adds a span around preact rendering, showing how long rendering
takes.
- Fresh adds a span around static file serving, showing how long it took
and whether there were requests without a cache bust key.
We can improve this in the future with more telemetry, such as metrics.
Avoids `\\\\` paths ending up in `snapshot.json` when using `deno task
build` on Windows. Backslashes do not which pathnames in URLs, so these
assets are not returned.
Closes#2703
The whole point of `asset()` is to enable caching. Yet we were not
adding cache control headers... :D
---------
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
I'm trying to migrate one of my projects which publishes a plugin, and
this was blocking me.
Looks like key is typed as `export type Key = string | number | any;`,
so we might need to make more changes here in the future.
The documentation for `MiddlewareFn` is out of date, because it
references a nonexistent `defineMiddleware` function. It's been updated
to reference the correct `define.middleware` function.
Additionally, I included an example of using this in the init project. I
also complicated the usage of `app.get` so that the function actually
uses the context. To make it clear to users of fresh 1 that this can be
equivalent to a file-based-route, I've included such a route as well.
The two new examples in `maini.ts` should make it much more clear to
fresh 1 users how the new system can work.
Ran into an issue where we weren't responding with the correct status
code and passed response headers. This was a bit of a rabbit hole and it
was caused by us wrapping to more error handling middlewares than
necessary.