Commit Graph
357 Commits
Author SHA1 Message Date
Marvin Hagemeister e3508c3054 feat: add ctx.redirect() helper (#2358)
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`.
2024-03-12 17:36:34 +01:00
Reed von Redwitz 5ec06350e2 fix: allow multiple set-cookie headers to be set before render (#2357)
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.
2024-03-12 12:04:42 +01:00
Reed von Redwitz 8f3031317b fix: properly prefix all scripts with base path (#2334)
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.
2024-02-23 13:30:42 +01:00
Marvin Hagemeister a2be1abc6b chore: update Preact to 10.19.6 (#2331) 2024-02-22 10:46:41 +01:00
Reed von Redwitz 82c75f85e9 fix: update dependency recommendations (#2320)
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/`.
2024-02-19 10:33:04 +01:00
Marvin Hagemeister aeca15eeb9 fix: open redirect issue with trailing slash detection (#2313)
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.
2024-02-14 15:25:16 +01:00
Roj [roːʒ] d19c22d592 feat: add back twind in init wizard (#2290) 2024-01-30 12:34:38 +01:00
Reed von Redwitz 3f28cc8977 chore: upgrade tailwind to 3.4.1 (#2287) 2024-01-29 14:10:28 +01:00
Reed von Redwitz a83765efaa fix: no-window lint error (#2272)
Latest PR runs are failing with linting errors, e.g.
https://github.com/denoland/fresh/actions/runs/7625625084/job/20770308634?pr=2266

Maybe this shouldn't be happening like this right now, but we'll still
need to clean these up eventually.
2024-01-23 21:51:38 +01:00
Marvin Hagemeister 9f81806c6e fix: __FRSH_STATE potentially being overwritten by user code (#2256)
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>`
2024-01-15 19:41:12 +01:00
Luca Casonato 8583394481 fix: prototype pollution in deserializer (#2255)
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.
2024-01-15 18:03:59 +00:00
Igor Brasileiro e7bf6aca62 fix: Prevent update doc title from partial if not present (#2244)
fixes #2243
2024-01-12 18:47:40 +01:00
Reed von Redwitz ca8338e04d chore: bump std to 0.211.0 and loader to 0.8.3 (#2241) 2024-01-11 15:54:41 +01:00
Marvin Hagemeister d2e9ee99a2 fix: browser url not updated with form partials (#2236)
Fixes https://github.com/denoland/fresh/issues/2173
2024-01-10 15:36:30 +01:00
Marvin Hagemeister 912f3782a3 feat: improve tailwind deployment flow (#2227)
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
2024-01-10 10:35:26 +01:00
Marvin Hagemeister f63752062a chore: change assert to with for import attributes (#2231) 2024-01-10 10:25:07 +01:00
Marvin Hagemeister 598237d5dd fix: json import attribute error in island (#2228)
Fixes https://github.com/denoland/fresh/issues/2214
2024-01-10 00:33:38 +01:00
Marvin Hagemeister 8c4385043c Revert "refactor: use --env CLI arg" (#2212)
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.
2024-01-04 11:53:15 +01:00
Asher Gomez 99eb5435bb refactor: use --env CLI arg (#2204)
This change replaces the use of the Standard Library's `dotenv.load()`
with the native `--env` CLI flag.

The benefits include:
* One less dependency
* More obvious consumption of the `.env` file in the CLI output
2023-12-29 10:47:15 +01:00
Marvin Hagemeister 498aa8c463 fix: don't fallthrough static files in dev (#2156) 2023-12-07 12:23:23 +01:00
Marvin Hagemeister c72f534369 fix: route param fallback not empty string (#2146) 2023-12-06 09:33:36 +01:00
Marvin Hagemeister c05a6b1496 fix: tailwind build not creating subfolders (#2145) 2023-12-06 08:57:31 +01:00
Reed von Redwitz 7465dbd978 feat(init): task to generate manifest file (#1422) 2023-12-05 15:03:37 +01:00
Reed von Redwitz 60b2198d13 fix: tailwind now respects basepath (#2138) 2023-12-05 13:13:33 +01:00
Reed von Redwitz c8844ad98c fix: PluginRoute supports AsyncRoute and AsyncLayout (#2139) 2023-12-04 16:56:00 +01:00
Christian SvenssonandMarvin Hagemeister 96644f5e22 fix: remove error frame HTML for non-dev mode (#2133)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2023-12-04 11:14:11 +00:00
Christian SvenssonandMarvin Hagemeister c4e09d1cef fix: use real 500 error page in dev mode (#2134)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2023-12-04 12:06:06 +01:00
迷渡andMarvin Hagemeister 87d1f2356a chore: Use satisfies instead of as (#2136)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2023-12-04 11:38:52 +01:00
Reed von Redwitz 35da45bff1 chore: update types in tests, init, update (#2122)
Of particular note is the change to
`tests/fixture_plugin/routes/test.tsx`. Note how I do this:
```diff
-  async GET(_req, ctx: HandlerContext<unknown, { test: string }>) {
+  async GET(_req, ctx: FreshContext<{ test: string }, unknown>) {
```

I find it strange and confusing that the order of the type parameters
has "changed". This makes it impossible to do a simple search and
replace, because people now have to change order as well.

Most of the types have been declared as `<T, S>`, i.e. data before
state:
* `PageProps<T = any, S = Record<string, unknown>>`
* `RouteContext<T = any, S = Record<string, unknown>>`
* `Handler<T = any, State = Record<string, unknown>>`
* `Handlers<T = any, State = Record<string, unknown>> `
* `AsyncRoute<T = any, S = Record<string, unknown>>`
* `PageComponent<T = any, S = Record<string, unknown>> `
* `AsyncLayout<T = any, S = Record<string, unknown>>`

And then `FreshContext` comes around like 
```
export interface FreshContext<
  State = Record<string, unknown>,
  // deno-lint-ignore no-explicit-any
  Data = any,
  NotFoundData = Data,
>
```
and switches it all up.

Not a huge issue, but just something to be aware of that others might
report.
2023-12-02 10:33:59 +01:00
Marvin Hagemeister 2acf72d512 fix: tailwind failing on non-existant files (#2118) 2023-12-01 23:38:22 +01:00
Marvin Hagemeister bd372b9535 fix: errors in plugin fixture + improve island docs (#2109) 2023-12-01 12:21:10 +01:00
Marvin Hagemeister 054ffbb44a fix: dots in island + route name not working (#2105) 2023-11-30 18:14:59 +01:00
Reed von Redwitz a0483bc357 chore: create manifest generation task (#2088) 2023-11-30 17:07:00 +01:00
Marvin Hagemeister 9e11c5c56b feat: expose config in context + simplify page props (#2102) 2023-11-30 16:11:31 +01:00
Marvin Hagemeister 8ddc21eb90 Router cleanup (#2099) 2023-11-30 14:08:05 +01:00
Marvin Hagemeister daf8ca19d2 chore: fix twind test (#2100) 2023-11-30 13:18:19 +01:00
Reed von RedwitzandMarvin Hagemeister 9ab8651018 feat(server): Add basePath config to host from a directory (#2092)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2023-11-29 16:44:25 +00:00
Marvin Hagemeister fe792455ab fix: add missing -h/--help to init (#2096) 2023-11-29 16:57:39 +01:00
Marvin Hagemeister a0ede4fe67 fix: incorrect path matching in tailwind plugin (#2094) 2023-11-29 16:37:54 +01:00
Reed von RedwitzandMarvin Hagemeister ad33501692 chore: remove $fresh from import statements (#2079)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2023-11-28 16:43:50 +00:00
Reed von RedwitzandMarvin Hagemeister b902205feb chore: bump std to 208 and deal with deprecations (#2081)
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2023-11-28 16:35:26 +00:00
Marvin Hagemeister 325850719a feat: reduce number of island bundles (#2082) 2023-11-28 17:23:27 +01:00
Marvin Hagemeister 9ee6ab72e0 fix: show original error page in dev (#2074) 2023-11-28 11:58:50 +01:00
Marvin Hagemeister a56ea283c8 fix: Partials not working on error pages (#2072) 2023-11-27 16:56:46 +01:00
Marvin Hagemeister 1294d455bc fix: client script source map returning 404 (#2071) 2023-11-27 16:10:36 +01:00
Marvin Hagemeister 9d5e916e4c fix: invalid identifier in manifest (#2070) 2023-11-27 11:20:40 +01:00
Reed von Redwitz 72edafde46 feat(server): plugins can create islands (#1472) 2023-11-22 11:19:13 +01:00
Reed von Redwitz ad2341dada chore: switch init to use tailwind (#2061) 2023-11-22 11:17:42 +01:00
Marvin Hagemeister bb035ae8da docs: port over to TailwindCSS (#2058) 2023-11-22 11:12:21 +01:00
Marvin Hagemeister f105f19005 fix: tailwind don't magically add content regex (#2060) 2023-11-21 20:59:02 +01:00