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.
Some team members of mine were confused by the default output
```
🍋 Fresh ready
Local: http://localhost:8000/
```
when the server is actually running HTTPS. This should now print
```
🍋 Fresh ready
Local: https://localhost:8000/
```
when a key and cert are specified.
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/`.
Passing a path like `/foo/bar` as the location header is interpreted as
a relative path. But when it contains two leading slashes like
`//evil.com/` it is interpreted as a port relative url. This has the
consequence that the origin of a URL can essentially be replaced:
```ts
new URL("//evil.com", "https://example.com/");
// -> 'https://evil.com/'
```
Our trailing slash detection logic didn't guard against this case. By
normalizing the pathname of the URL and stripping sibling forward
slashes we sidestep this problem.
I tested the change in my own repo, the warning on github disapears for
the "actions/checkout" action.
It is still there for the denoland/setup-deno action, but an upgrade PR
is already ongoing for this action, see:
https://github.com/denoland/setup-deno/pull/56