On my machine, reduces time taken to perform `deno task test` from
~1m20s to ~30s.
Inspired by and supersedes #2110.
---------
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
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.
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>
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.
Overhauls the Fresh homepage with a new design, new demos, and new
sections highlighting Fresh's capabilities.
---------
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
Newer Deno versions have an additional `completed` property in there.
This PR allows Fresh to be used with both old and newer Deno versions
without getting type errors.
This PR adds a `ctx.redirect(path, status)` helper that aims to reduce
the verbosity of having to manually create a `Response` obejct for a
mere redirect.
```ts
// Before
new Response(null, {
status: 307,
headers: {
Location: "/foo/bar"
},
})
// After
ctx.redirect("/foo/bar", 307)
```
If the second parameter is not passed, it will default to `302`.
closes#2346
The primary issue was the snippet `headers[key] = value`. This caused
only one `set-cookie` to make it through. Switching to a `Headers`
object allowed me to use `append` when appropriate, allowing for
multiple `set-cookie` entries.
I also cleaned up one of the tests to make use of steps, because I
originally broke it and couldn't immediately tell which part was
failing.
closes https://github.com/denoland/fresh/issues/2326
There was a big misunderstanding on my part -- in particular that a
different server might be listening at the root, so the redirect built
into `context.ts` will never happen. The existing test (as mentioned in
the issue) passes, but only because no one else is listening, and fresh
is able to perform the redirect.
I briefly considered writing a docker container to orchestrate this
properly, but then I didn't want to have docker running in order to run
these tests. (My laptop is old and bad.) So instead the two new tests
very thoroughly assert that scripts included in the html are properly
prefixed with the base path. And yes, they fail if the fix is reverted.
As for the fix itself: I just needed to prepend the asset URL with the
base path.
closes https://github.com/denoland/fresh/issues/2319
The issue is because `imports.ts` wasn't changed before releasing. I
thought I would go through and bump some other versions as well. This
handles everything except the esbuild stuff and `tests/`.