Commit Graph
33 Commits
Author SHA1 Message Date
Asher Gomez 5ef6fa34d9 fix: use await Deno.serve().finished (#1287)
[A recent change in the
runtime](https://github.com/denoland/deno/pull/19485) has changed the
behaviour of `Deno.serve()` such that it throws when called a promise.
The correct way to do it is instead to call `Deno.serve().finished` as a
promise. This PR does that.

Fixes
https://github.com/denoland/fresh/pull/1286#issuecomment-1589987387
2023-06-14 08:23:51 +10:00
Marvin Hagemeister 36d56a9878 feat(server): pick free port if none specified (#1274) 2023-06-12 13:18:52 +02:00
Marvin Hagemeister 69f4fecf5a feat(server): make startup message easier to see (#1273) 2023-06-12 10:42:17 +02:00
Savin Angel-MarioandAsher Gomez 6e1874ccca feat: use PORT environment variable to change port (#468)
This can be useful when deploying to other providers.

Also more convenient for projects with multiple developers with port
preferences

---------

Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
2023-06-05 09:08:46 +02:00
Asher GomezandLuca Casonato 1b6678951a feat: support embedded import map in deno.json (#1188)
One can now inline the `imports` and `scopes` from the import map directly into deno.json.

For new projects, `import_map.json` is not generated anymore.

Co-authored-by: Luca Casonato <hello@lcas.dev>
2023-06-03 10:46:40 +02:00
Octo8080X 675036b33c feat: add createHandler() (#622)
I cut out the function that gets an hundler from fresh.

The purpose is to prepare you to create tests for your application.
The introduction of this feature does not affect fresh.

Example:

```typescript main_test.ts
/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />
/// <reference lib="deno.unstable" />

import { createHandler } from "$fresh/server.ts";
import manifest from "./fresh.gen.ts";

import { superdeno } from "https://deno.land/x/superdeno/mod.ts";
import { assertEquals } from "https://deno.land/std@0.148.0/testing/asserts.ts";
import {
  type RequestHandlerLike,
} from "https://deno.land/x/superdeno/src/types.ts";
import {
  Document,
  DOMParser,
} from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";


Deno.test("HTTP assert test.", async (t) => {
  await t.step("#1 GET /", async () => {
    const handler = await createHandler(manifest) as RequestHandlerLike;

    await superdeno(handler)
      .get("/")
      .expect(200);
  });
  await t.step("#2 GET /Foo", async () => {
    const server = await createHandler(manifest) as RequestHandlerLike;

    const r = await superdeno(server)
      .get("/Foo")
      .expect(200);

    const document: Document = new DOMParser().parseFromString(
      r.text,
      "text/html",
    )!;

    assertEquals(document.querySelector("div")?.innerText, "Hello Foo");
  });

  await t.step("#3 GET /Foo/Bar", async () => {
    const server = await createHandler(manifest) as RequestHandlerLike;

    await superdeno(server)
      .get("/Foo/Bar")
      .expect(404);
  });
});
```

```sh
$ deno test -A main_test.ts
Check file:///usr/src/app/my-project/main_test.ts
running 1 test from ./main_test.ts
HTTP assert test. ...
  #1 GET / ... ok (53ms)
  #2 GET /Foo ... ok (50ms)
  #3 GET /Foo/Bar ... ok (45ms)
HTTP assert test. ... ok (154ms)

ok | 1 passed (3 steps) | 0 failed (300ms)
```

This was discussed in a separate pull request, but prepared in a
separate branch based on @lucacasonato suggestion.

[Add a function to get a server class
instance.](https://github.com/denoland/fresh/pull/552)

Thenk you.
2023-05-30 10:29:26 +10:00
Mark BennettandLuca Casonato ba7c78bcc2 feat: experimental support for Deno.serve (#681)
The experimental support can be enabled through the
`experimentalDenoServe` option for `start()`.

Co-authored-by: Luca Casonato <hello@lcas.dev>
2022-09-07 23:04:45 +00:00
Luca Casonato b12867a582 feat: support JSX automatic mode (#610)
This commit adds support for JSX automatic mode instead of the default
mode that requires the presence of the JSX pragma in each file.

This commit also adds the config file to the `fresh.gen.ts` manifest,
which is used to determine if the client emit should use automatic mode.

The minimum Deno version has also been bumped to 1.25.0.
2022-08-26 11:03:00 +02:00
ahuigo a00b97bac9 feat: support multiple middlewares with the same matcher (#553) 2022-08-23 23:50:57 +02:00
Luca Casonato fd4e2bbe17 feat: add initial plugin support (#512)
This commit adds initial support for fresh "plugins". These are bundles
of functionality that can be added to a fresh plugin through a simple
addition in the `main.ts` file.

Right now plugins are only able to hook into the render steps. This
means that they can inject styling and scripts. They can not yet hook
into routing.

Things that I think should be possible now:
- styling integrations for twind, unocss, and probably a few other tools

Things that are not possible yet:
- google analytics middleware
- database connectors
- CMS connectors

The routing additions to plugins can be added in a follow-up though.
2022-08-09 21:27:58 +02:00
AbdulazizandLuca Casonato 1dc1f87fc3 refactor: use named status codes from std internally (#417)
Co-authored-by: Luca Casonato <hello@lcas.dev>
2022-07-30 15:35:31 +00:00
Luca Casonato ba20756c17 chore: update deps (#561)
Update std, esbuild, and preact.
2022-07-30 17:29:29 +02:00
Luca Casonato da340daeb2 BREAKING: move a bunch of types into server/ (#263)
Moved some server only types like `RouteConfig` into server/. They were
previously in runtime/.
2022-06-21 15:21:07 +02:00
Luca Casonato 70d1838cad BREAKING: make render fn an option on start (#260)
This commit removes the `_render.{tj}s{x}?` file in favor of a `render` option on the `start` call in `main.ts`.
2022-06-20 13:40:23 +02:00
Elias SjögreenandLuca Casonato 34dc19a2f9 feat: support specifying hostname and port in start (#150)
Co-authored-by: Luca Casonato <hello@lcas.dev>
2022-04-23 15:24:29 +02:00
Leo Kettmeir cf48eafa9a BREAKING refactor: detach request from handler context (#114) 2022-03-06 18:25:50 +01:00
Luca Matei Pintilie 623e4b7605 chore: update dependencies (#112) 2022-03-06 13:33:18 +01:00
Luca Casonato 8daa280862 feat: a new "island" based architechture (#97) 2022-03-04 19:49:27 +01:00
Leo KettmeirandLuca Casonato 04a32f3498 feat: _app (#87)
Co-authored-by: Luca Casonato <hello@lcas.dev>
2022-02-18 19:30:24 +01:00
Luca Casonato aa1e1bcdb4 feat: add support for middleware (#74) 2021-11-01 13:35:41 +01:00
Luca Casonato 75afa6daca feat: add static file support (#58)
This commit adds support for serving static files. Static can be placed
into the `/static` directory (as a sibling of the `/pages` directory).
2021-09-25 13:37:46 +02:00
Luca Casonato f5b3faf0d8 BREAKING: merge API routes and pages concept (#53)
This commit merges API routes and pages into a single concept. The
pages/api folder is now not special anymore.
2021-09-25 10:49:53 +02:00
Luca Casonato 3bce2fb8d3 feat: deployctl is not needed anymore (#45)
Deno Deploy now supports Deno.listen and Deno.serveHttp.
2021-07-30 14:09:04 +02:00
Luca Casonato 940f34d811 feat: add custom render function support (#30) 2021-06-16 19:36:12 +02:00
Luca Casonato 572b8123c4 refactor: centralize server into ServerContext (#26)
This commit centralizes all server related logic into a central
ServerContext class.
2021-06-10 20:46:10 +02:00
Leo K a48da64dc3 feat: change to denosaurs router (#20) 2021-06-03 11:11:04 +02:00
Luca Casonato 26189cfdf3 tests: add basic integration tests (#13) 2021-06-02 01:16:31 +02:00
Luca Casonato ff69a0abdf feat: add api routes (#11)
This commit adds API routes. These routes are located in the
./pages/api/ directory. Each file in there will have it's default
export invoked for HTTP calls to the corresponding route.
2021-06-02 00:15:00 +02:00
Luca Casonato 31dbd99bea chore: improve bundling + refactor router (#10)
This commit changes how bundling works, by bundling all routes at once.
Static JS assets are now cached immutably.

Additionally this PR completly refactors how the router works to make it
more modular. This allows users to opt out of the default oak server,
and instead create their own.
2021-06-01 23:19:33 +02:00
Luca Casonato 9145711e2e remove need for export function self 2021-05-08 03:12:56 +02:00
Luca Casonato 2e4b4db421 error 2021-05-08 02:09:49 +02:00
Luca Casonato 4c3dfe6273 err 2021-05-08 02:09:35 +02:00
Luca Casonato 6ecdf2ed73 init 2021-05-08 02:07:24 +02:00