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.
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.
https://biomejs.dev/linter/rules/use-import-type/
From that page the argument is
>The rule ensures that all imports used only as a type use a type-only
import. It also groups inline type imports into a grouped import type.
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.