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/`.
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.
As outlined in https://github.com/denoland/fresh/issues/2254 it was
possible to overwrite the script tag that is used by Fresh to pass
island props from the server to the client. This could be done by
injecting raw HTML via `dangerouslySetInnerHTML` and simply using the
same id that Fresh was using.
With this PR we generate a unique id per render that cannot be guessed
anymore. It's composed of `__FRSH_STATE_<uuid>`
This is not exploitable in practice unless a user maliciously crafts
serialized values in __FRSH_STATE, because `serializer()` never outputs
serialized representation that would be vulnerable to prototype
pollution. But hey, defense in depth.
By moving folks from `twind` over to the `tailwind` plugin we have
traded support questions about "how to get twind autocompletion
working?" with "my styles are not showing up in automatic mode". The
tailwind plugin has a hard requirement on having a build step. We have
documented this at various places and have a guide on how to set
everything up, but it's much better if we float those steps from Fresh
itself when we detect this.
With this PR we will prepare a `.github/workflows/deploy.yml` file
already where the user only needs to swap out the project name.
When Fresh is started in production mode, the tailwind plugin is active
and no snapshot files were loaded, then we print a helpful hint to the
console:
```sh
No pre-compiled tailwind styles found.
Did you forget to run "deno task build" prior to starting the production server?
```
When we are running inside Deno Deploy this PR goes one step further.
Since it is the first time many users might use Deno Deploy we'll also
show a simple page that shows how to finish the tailwind setup. I've
intentionally tried to not present this as a warning but rather as a
"finishing" step to avoid scaring users off. It's not the prettiest
page, but it's good enough for now.
<img width="892" alt="Screenshot 2024-01-09 at 23 41 27"
src="https://github.com/denoland/fresh/assets/1062408/9bf2a61b-5551-4d8e-bdf8-b498072f8e98">
Fixes https://github.com/denoland/fresh/issues/2223
Reverts denoland/fresh#2204
The `--env` flag cannot be used by default because it fails when no
`.env` file is present. Therefore this PR accidentally introduced a
breaking change.