diff --git a/README.md b/README.md index 42a96be6..17dbd8f9 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ The [documentation](https://fresh.deno.dev/docs/) is available on ## 🚀 Getting started -Install [Deno CLI](https://deno.land/) version 1.31.0 or higher. +Install [Deno CLI](https://deno.land/) version 1.35.0 or higher. You can scaffold a new project by running the Fresh init script. To scaffold a project run the following: diff --git a/docs/canary/concepts/middleware.md b/docs/canary/concepts/middleware.md index b04f1464..5f272f10 100644 --- a/docs/canary/concepts/middleware.md +++ b/docs/canary/concepts/middleware.md @@ -120,11 +120,15 @@ the value of `acme` in your middleware. To set the stage for this section, `MiddlewareHandlerContext` looks like this: ```ts -export interface MiddlewareHandlerContext> - extends ConnInfo { +export interface MiddlewareHandlerContext> { next: () => Promise; state: State; destination: router.DestinationKind; + remoteAddr: { + transport: "tcp" | "udp"; + hostname: string; + port: number; + }; } ``` diff --git a/docs/concepts/deployment.md b/docs/concepts/deployment.md index 051d0d54..14e3586d 100644 --- a/docs/concepts/deployment.md +++ b/docs/concepts/deployment.md @@ -36,7 +36,7 @@ caching **will** cause your project to not function correctly. Here is an example `Dockerfile` for a Fresh project: ```dockerfile -FROM denoland/deno:1.33.2 +FROM denoland/deno:1.35.0 ARG GIT_REVISION ENV DENO_DEPLOYMENT_ID=${GIT_REVISION} diff --git a/docs/concepts/middleware.md b/docs/concepts/middleware.md index 834ffcec..72412c22 100644 --- a/docs/concepts/middleware.md +++ b/docs/concepts/middleware.md @@ -100,11 +100,15 @@ export const handler = [ To set the stage for this section, `MiddlewareHandlerContext` looks like this: ```ts -export interface MiddlewareHandlerContext> - extends ConnInfo { +export interface MiddlewareHandlerContext> { next: () => Promise; state: State; destination: router.DestinationKind; + remoteAddr: { + transport: "tcp" | "udp"; + hostname: string; + port: number; + }; } ``` diff --git a/docs/concepts/server-configuration.md b/docs/concepts/server-configuration.md index 698ed965..393dad8a 100644 --- a/docs/concepts/server-configuration.md +++ b/docs/concepts/server-configuration.md @@ -17,19 +17,10 @@ export async function start(routes: Manifest, opts: StartOptions = {}); things get interesting. `StartOptions` looks like this: ``` -export type StartOptions = ServeInit & FreshOptions & { - /** - * UNSTABLE: use the `Deno.serve` API as the underlying HTTP server instead of - * the `std/http` API. Do not use this in production. - * - * This option is experimental and may be removed in a future Fresh release. - */ - experimentalDenoServe?: boolean; -}; +export type StartOptions = ServeInit & FreshOptions; ``` -You can play around with `Deno.serve` if you'd like, but heed the warning. The -good stuff is really in... +The good stuff is really in... ```ts export interface FreshOptions { diff --git a/docs/concepts/updating.md b/docs/concepts/updating.md index 44973b77..ed8265ab 100644 --- a/docs/concepts/updating.md +++ b/docs/concepts/updating.md @@ -23,6 +23,7 @@ below. | 1.0.0-1.0.2 | >=10.8.1 <11.0.0 | >=5.2.0 <6.0.0 | >= 1.23.0 | | 1.1.0-1.1.5 | >=10.8.1 <11.0.0 | >=5.2.0 <6.0.0 | >= 1.25.0 | | 1.2.0 | >=10.15.0 <11.0.0 | >=6.1.0 | >= 1.25.0 | +| 1.3.0 | >=10.15.0 <11.0.0 | >=6.1.0 | >= 1.35.0 | ## Updating dependencies diff --git a/docs/examples/writing-tests.md b/docs/examples/writing-tests.md index 7d5a251a..fe675d98 100644 --- a/docs/examples/writing-tests.md +++ b/docs/examples/writing-tests.md @@ -53,13 +53,11 @@ export default function FooPage() { ```ts // tests/main_test.ts -import { createHandler } from "$fresh/server.ts"; +import { createHandler, ServeHandlerInfo } from "$fresh/server.ts"; import manifest from "../fresh.gen.ts"; import { assert, assertEquals } from "$std/testing/asserts.ts"; -import type { ConnInfo } from "$std/http/server.ts"; -const CONN_INFO: ConnInfo = { - localAddr: { hostname: "127.0.0.1", port: 8000, transport: "tcp" }, +const CONN_INFO: ServeHandlerInfo = { remoteAddr: { hostname: "127.0.0.1", port: 53496, transport: "tcp" }, }; diff --git a/docs/getting-started/index.md b/docs/getting-started/index.md index 4568906d..3fdb2dad 100644 --- a/docs/getting-started/index.md +++ b/docs/getting-started/index.md @@ -10,7 +10,7 @@ framework. You'll learn how to create a new project, run it locally, edit and create pages, fetch data, handle user interactions, and how to then deploy the project to [Deno Deploy][deno-deploy]. -The documentation assumes you have Deno 1.31.0 or later installed. +The documentation assumes you have Deno 1.35.0 or later installed. To install Deno, follow the [installation instructions in the Deno manual][manual-installation]. diff --git a/src/server/context.ts b/src/server/context.ts index 937c0d0a..79cf1739 100644 --- a/src/server/context.ts +++ b/src/server/context.ts @@ -1,5 +1,4 @@ import { - ConnInfo, dirname, extname, fromFileUrl, @@ -33,6 +32,7 @@ import { Route, RouteModule, RouterOptions, + ServeHandlerInfo, UnknownPage, UnknownPageModule, } from "./types.ts"; @@ -47,7 +47,7 @@ import { } from "../build/mod.ts"; import { InternalRoute } from "./router.ts"; -const DEFAULT_CONN_INFO: ConnInfo = { +const DEFAULT_CONN_INFO: ServeHandlerInfo = { localAddr: { transport: "tcp", hostname: "localhost", port: 8080 }, remoteAddr: { transport: "tcp", hostname: "localhost", port: 1234 }, }; @@ -374,7 +374,7 @@ export class ServerContext { * This functions returns a request handler that handles all routes required * by fresh, including static files. */ - handler(): (req: Request, connInfo?: ConnInfo) => Promise { + handler(): (req: Request, connInfo?: ServeHandlerInfo) => Promise { const handlers = this.#handlers(); const inner = router.router(handlers); const withMiddlewares = this.#composeMiddlewares( @@ -385,7 +385,7 @@ export class ServerContext { const trailingSlashEnabled = this.#routerOptions?.trailingSlash; return async function handler( req: Request, - connInfo: ConnInfo = DEFAULT_CONN_INFO, + connInfo: ServeHandlerInfo = DEFAULT_CONN_INFO, ) { // Redirect requests that end with a trailing slash to their non-trailing // slash counterpart. @@ -457,7 +457,7 @@ export class ServerContext { ) { return ( req: Request, - connInfo: ConnInfo, + connInfo: ServeHandlerInfo, inner: router.FinalHandler, ) => { // identify middlewares to apply, if any. diff --git a/src/server/deps.ts b/src/server/deps.ts index bda78737..16c9ec2f 100644 --- a/src/server/deps.ts +++ b/src/server/deps.ts @@ -11,10 +11,7 @@ export { type Handler as ServeHandler, serve, } from "https://deno.land/std@0.193.0/http/server.ts"; -export type { - ConnInfo, - ServeInit, -} from "https://deno.land/std@0.193.0/http/server.ts"; +export type { ServeInit } from "https://deno.land/std@0.193.0/http/server.ts"; export { Status } from "https://deno.land/std@0.193.0/http/http_status.ts"; export { typeByExtension, diff --git a/src/server/mod.ts b/src/server/mod.ts index 35b6d003..df464aae 100644 --- a/src/server/mod.ts +++ b/src/server/mod.ts @@ -1,13 +1,15 @@ import { ServerContext } from "./context.ts"; import * as colors from "https://deno.land/std@0.193.0/fmt/colors.ts"; -import { ConnInfo, serve, ServeHandler } from "./deps.ts"; export { Status } from "./deps.ts"; +import { serve } from "./deps.ts"; import { AppModule, ErrorPageModule, IslandModule, MiddlewareModule, RouteModule, + ServeHandler, + ServeHandlerInfo, StartOptions, UnknownPageModule, } from "./types.ts"; @@ -35,6 +37,7 @@ export type { PluginRenderStyleTag, RenderFunction, RouteConfig, + ServeHandlerInfo, StartOptions, UnknownHandler, UnknownHandlerContext, @@ -70,7 +73,9 @@ export { ServerContext }; export async function createHandler( routes: Manifest, opts: StartOptions = {}, -): Promise<(req: Request, connInfo?: ConnInfo) => Promise> { +): Promise< + (req: Request, connInfo?: ServeHandlerInfo) => Promise +> { const ctx = await ServerContext.fromManifest(routes, opts); return ctx.handler(); } @@ -132,10 +137,12 @@ export async function start(routes: Manifest, opts: StartOptions = {}) { } async function bootServer(handler: ServeHandler, opts: StartOptions) { - if (opts.experimentalDenoServe === true) { - // @ts-ignore as `Deno.serve` is still unstable. - await Deno.serve({ ...opts, handler }).finished; + // @ts-ignore Ignore type error when type checking with Deno versions + if (typeof Deno.serve === "function") { + // @ts-ignore Ignore type error when type checking with Deno versions + await Deno.serve(opts, handler).finished; } else { + // @ts-ignore Deprecated std serve way await serve(handler, opts); } } diff --git a/src/server/router.ts b/src/server/router.ts index ee6d53ae..e056e108 100644 --- a/src/server/router.ts +++ b/src/server/router.ts @@ -1,6 +1,6 @@ -import type { ConnInfo } from "./deps.ts"; +import { ServeHandlerInfo } from "./types.ts"; -type HandlerContext = T & ConnInfo; +type HandlerContext = T & ServeHandlerInfo; export type Handler = ( req: Request, diff --git a/src/server/types.ts b/src/server/types.ts index 390c5aee..c13dae40 100644 --- a/src/server/types.ts +++ b/src/server/types.ts @@ -1,19 +1,11 @@ import { ComponentType } from "preact"; -import { ConnInfo, ServeInit } from "./deps.ts"; +import { ServeInit } from "./deps.ts"; import * as router from "./router.ts"; import { InnerRenderFunction, RenderContext } from "./render.ts"; // --- APPLICATION CONFIGURATION --- -export type StartOptions = ServeInit & FreshOptions & { - /** - * UNSTABLE: use the `Deno.serve` API as the underlying HTTP server instead of - * the `std/http` API. Do not use this in production. - * - * This option is experimental and may be removed in a future Fresh release. - */ - experimentalDenoServe?: boolean; -}; +export type StartOptions = ServeInit & FreshOptions; export interface FreshOptions { render?: RenderFunction; @@ -85,8 +77,22 @@ export interface RouteConfig { // deno-lint-ignore no-empty-interface export interface RenderOptions extends ResponseInit {} +export type ServeHandlerInfo = { + /** + * Backwards compatible with std/server + * @deprecated + */ + localAddr?: Deno.NetAddr; + remoteAddr: Deno.NetAddr; +}; + +export type ServeHandler = ( + request: Request, + info: ServeHandlerInfo, +) => Response | Promise; + export interface HandlerContext> - extends ConnInfo { + extends ServeHandlerInfo { params: Record; render: ( data?: Data, @@ -158,7 +164,7 @@ export interface UnknownPageProps { } export interface UnknownHandlerContext> - extends ConnInfo { + extends ServeHandlerInfo { render: () => Response | Promise; state: State; } @@ -198,7 +204,7 @@ export interface ErrorPageProps { } export interface ErrorHandlerContext> - extends ConnInfo { + extends ServeHandlerInfo { error: unknown; render: () => Response | Promise; state: State; @@ -227,7 +233,7 @@ export interface ErrorPage { // --- MIDDLEWARES --- export interface MiddlewareHandlerContext> - extends ConnInfo { + extends ServeHandlerInfo { next: () => Promise; state: State; destination: router.DestinationKind; diff --git a/tests/error_test.ts b/tests/error_test.ts index 4ce2a0d1..b8a0c449 100644 --- a/tests/error_test.ts +++ b/tests/error_test.ts @@ -7,11 +7,6 @@ const ctx = await ServerContext.fromManifest(manifest, {}); const handler = ctx.handler(); const router = (req: Request) => { return handler(req, { - localAddr: { - transport: "tcp", - hostname: "127.0.0.1", - port: 80, - }, remoteAddr: { transport: "tcp", hostname: "127.0.0.1", diff --git a/tests/fixture/main.ts b/tests/fixture/main.ts index da8c854a..1409a21d 100644 --- a/tests/fixture/main.ts +++ b/tests/fixture/main.ts @@ -8,6 +8,4 @@ import { start } from "$fresh/server.ts"; import routes from "./fresh.gen.ts"; import options from "./options.ts"; -const experimentalDenoServe = Deno.args.includes("--experimental-deno-serve"); - -await start(routes, { ...options, experimentalDenoServe }); +await start(routes, options); diff --git a/tests/fixture/main_wasm.ts b/tests/fixture/main_wasm.ts index a48ed37c..946b1ede 100644 --- a/tests/fixture/main_wasm.ts +++ b/tests/fixture/main_wasm.ts @@ -11,6 +11,4 @@ import { start } from "$fresh/server.ts"; import routes from "./fresh.gen.ts"; import options from "./options.ts"; -const experimentalDenoServe = Deno.args.includes("--experimental-deno-serve"); - -await start(routes, { ...options, experimentalDenoServe }); +await start(routes, options); diff --git a/tests/fixture_island_nesting/main.ts b/tests/fixture_island_nesting/main.ts index f6b0fc28..bb97cc80 100644 --- a/tests/fixture_island_nesting/main.ts +++ b/tests/fixture_island_nesting/main.ts @@ -7,6 +7,4 @@ import { start } from "$fresh/server.ts"; import routes from "./fresh.gen.ts"; -const experimentalDenoServe = Deno.args.includes("--experimental-deno-serve"); - -await start(routes, { experimentalDenoServe }); +await start(routes); diff --git a/tests/fixture_island_nesting/main_wasm.ts b/tests/fixture_island_nesting/main_wasm.ts index 66b916c8..714834e6 100644 --- a/tests/fixture_island_nesting/main_wasm.ts +++ b/tests/fixture_island_nesting/main_wasm.ts @@ -10,6 +10,4 @@ import "./polyfill_deno_deploy.ts"; import { start } from "$fresh/server.ts"; import routes from "./fresh.gen.ts"; -const experimentalDenoServe = Deno.args.includes("--experimental-deno-serve"); - -await start(routes, { experimentalDenoServe }); +await start(routes); diff --git a/tests/fixture_preact_rts_v5/main.ts b/tests/fixture_preact_rts_v5/main.ts index da8c854a..1409a21d 100644 --- a/tests/fixture_preact_rts_v5/main.ts +++ b/tests/fixture_preact_rts_v5/main.ts @@ -8,6 +8,4 @@ import { start } from "$fresh/server.ts"; import routes from "./fresh.gen.ts"; import options from "./options.ts"; -const experimentalDenoServe = Deno.args.includes("--experimental-deno-serve"); - -await start(routes, { ...options, experimentalDenoServe }); +await start(routes, options); diff --git a/tests/fixture_preact_rts_v5/main_wasm.ts b/tests/fixture_preact_rts_v5/main_wasm.ts index a48ed37c..946b1ede 100644 --- a/tests/fixture_preact_rts_v5/main_wasm.ts +++ b/tests/fixture_preact_rts_v5/main_wasm.ts @@ -11,6 +11,4 @@ import { start } from "$fresh/server.ts"; import routes from "./fresh.gen.ts"; import options from "./options.ts"; -const experimentalDenoServe = Deno.args.includes("--experimental-deno-serve"); - -await start(routes, { ...options, experimentalDenoServe }); +await start(routes, options); diff --git a/tests/main_test.ts b/tests/main_test.ts index 73257d09..4e53a472 100644 --- a/tests/main_test.ts +++ b/tests/main_test.ts @@ -269,11 +269,6 @@ Deno.test("static files in custom directory", async () => { }); const newRouter = (req: Request) => { return newCtx.handler()(req, { - localAddr: { - transport: "tcp", - hostname: "127.0.0.1", - port: 80, - }, remoteAddr: { transport: "tcp", hostname: "127.0.0.1", @@ -670,67 +665,6 @@ Deno.test({ }, }); -Deno.test("experimental Deno.serve", { - sanitizeOps: false, - sanitizeResources: false, - ignore: Deno.build.os === "windows", // TODO: Deno.serve hang on Windows? -}, async (t) => { - // Preparation - const { serverProcess, lines, address } = await startFreshServer({ - args: [ - "run", - "-A", - "--unstable", - "./tests/fixture/main.ts", - "--experimental-deno-serve", - ], - }); - - await delay(100); - - await t.step("ssr", async () => { - const resp = await fetch(address); - assert(resp); - assertEquals(resp.status, Status.OK); - assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8"); - assertEquals(resp.headers.get("server"), "fresh test server"); - const body = await resp.text(); - assertStringIncludes(body, ``); - assertStringIncludes(body, "test_default.js"); - assertStringIncludes(body, "

Hello!

"); - assertStringIncludes(body, "

Viewing JIT render.

"); - assertStringIncludes(body, `>{"v":[[{"message":"Hello!"}],[]]}`); - assertStringIncludes( - body, - '', - ); - assertStringIncludes( - body, - '', - ); - assert( - !body.includes("specialTag"), - `Expected actual: "${body}" to not contain: "specialTag"`, - ); - }); - - await t.step("static file", async () => { - const resp = await fetch(`${address}/foo.txt`); - assertEquals(resp.status, Status.OK); - const body = await resp.text(); - assert(body.startsWith("bar")); - const etag = resp.headers.get("etag"); - assert(etag); - // TODO(kt3k): Enable this assertion when new Deno.serve is released. - // https://github.com/denoland/deno/pull/18568 - // assert(etag.startsWith("W/"), "etag should be weak"); - assertEquals(resp.headers.get("content-type"), "text/plain"); - }); - - await lines.cancel(); - serverProcess.kill("SIGTERM"); -}); - Deno.test("jsx pragma works", { sanitizeOps: false, sanitizeResources: false, diff --git a/tests/plugin_test.ts b/tests/plugin_test.ts index 320ff307..3f91ef6e 100644 --- a/tests/plugin_test.ts +++ b/tests/plugin_test.ts @@ -14,11 +14,6 @@ const ctx = await ServerContext.fromManifest(manifest, options); const handler = ctx.handler(); const router = (req: Request) => { return handler(req, { - localAddr: { - transport: "tcp", - hostname: "127.0.0.1", - port: 80, - }, remoteAddr: { transport: "tcp", hostname: "127.0.0.1", diff --git a/tests/trailing_slash_test.ts b/tests/trailing_slash_test.ts index 1df29a1f..7947bcd7 100644 --- a/tests/trailing_slash_test.ts +++ b/tests/trailing_slash_test.ts @@ -10,11 +10,6 @@ const ctx = await ServerContext.fromManifest(manifest, { }); const router = (req: Request) => { return ctx.handler()(req, { - localAddr: { - transport: "tcp", - hostname: "127.0.0.1", - port: 80, - }, remoteAddr: { transport: "tcp", hostname: "127.0.0.1", diff --git a/www/routes/_middleware.ts b/www/routes/_middleware.ts index e9228591..ed047227 100644 --- a/www/routes/_middleware.ts +++ b/www/routes/_middleware.ts @@ -61,6 +61,7 @@ function ga4( // Create basic report. const measurementId = GA4_MEASUREMENT_ID; + // @ts-ignore GA4Report doesn't even use the localAddress parameter const report = new GA4Report({ measurementId, request, response, conn }); // Override the default (page_view) event.