fix: ServerhandlerInfo type for newer Deno versions (#2419)

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 commit is contained in:
Marvin Hagemeister
2024-05-02 20:41:33 +02:00
committed by GitHub
parent bc75101dcf
commit 40181142d2
7 changed files with 27 additions and 17 deletions
+13 -9
View File
@@ -79,15 +79,19 @@ async function bootServer(
// @ts-ignore Ignore type error when type checking with Deno versions // @ts-ignore Ignore type error when type checking with Deno versions
await Deno.serve( await Deno.serve(
opts, opts,
(r, { remoteAddr }) => (r, info) =>
handler(r, { handler(
remoteAddr, r,
localAddr: { {
transport: "tcp", ...info,
hostname: opts.hostname ?? "localhost", remoteAddr: info.remoteAddr,
port: opts.port, localAddr: {
} as Deno.NetAddr, transport: "tcp",
}), hostname: opts.hostname ?? "localhost",
port: opts.port,
} as Deno.NetAddr,
},
),
).finished; ).finished;
} else { } else {
// @ts-ignore Deprecated std serve way // @ts-ignore Deprecated std serve way
+3 -1
View File
@@ -46,7 +46,9 @@ import { withBase } from "./router.ts";
import { PARTIAL_SEARCH_PARAM } from "../constants.ts"; import { PARTIAL_SEARCH_PARAM } from "../constants.ts";
import TailwindErrorPage from "./tailwind_aot_error_page.tsx"; import TailwindErrorPage from "./tailwind_aot_error_page.tsx";
const DEFAULT_CONN_INFO: ServeHandlerInfo = { // TODO: Completed type clashes in older Deno versions
// deno-lint-ignore no-explicit-any
const DEFAULT_CONN_INFO: any = {
localAddr: { transport: "tcp", hostname: "localhost", port: 8080 }, localAddr: { transport: "tcp", hostname: "localhost", port: 8080 },
remoteAddr: { transport: "tcp", hostname: "localhost", port: 1234 }, remoteAddr: { transport: "tcp", hostname: "localhost", port: 1234 },
}; };
+1 -2
View File
@@ -251,13 +251,12 @@ export interface RouteConfig {
export interface RenderOptions extends ResponseInit {} export interface RenderOptions extends ResponseInit {}
export type ServeHandlerInfo = { export type ServeHandlerInfo = Deno.ServeHandlerInfo & {
/** /**
* Backwards compatible with std/server * Backwards compatible with std/server
* @deprecated * @deprecated
*/ */
localAddr?: Deno.NetAddr; localAddr?: Deno.NetAddr;
remoteAddr: Deno.NetAddr;
}; };
export type ServeHandler = ( export type ServeHandler = (
+2 -1
View File
@@ -305,7 +305,8 @@ Deno.test("static files in custom directory", async () => {
hostname: "127.0.0.1", hostname: "127.0.0.1",
port: 80, port: 80,
}, },
}); // deno-lint-ignore no-explicit-any
} as any);
}; };
const resp = await newRouter( const resp = await newRouter(
+4 -2
View File
@@ -29,7 +29,8 @@ const router = (req: Request) => {
hostname: "127.0.0.1", hostname: "127.0.0.1",
port: 80, port: 80,
}, },
}); // deno-lint-ignore no-explicit-any
} as any);
}; };
Deno.test("/static page prerender", async () => { Deno.test("/static page prerender", async () => {
@@ -98,7 +99,8 @@ Deno.test("plugin routes and middleware -- async _app", async () => {
hostname: "127.0.0.1", hostname: "127.0.0.1",
port: 80, port: 80,
}, },
}); // deno-lint-ignore no-explicit-any
} as any);
}; };
const resp = await router(new Request("https://fresh.deno.dev/test")); const resp = await router(new Request("https://fresh.deno.dev/test"));
+2 -1
View File
@@ -289,7 +289,8 @@ export async function fakeServe(
const ctx = await ServerContext.fromManifest(manifest, config); const ctx = await ServerContext.fromManifest(manifest, config);
const handler = ctx.handler(); const handler = ctx.handler();
const conn: ServeHandlerInfo = { // deno-lint-ignore no-explicit-any
const conn: any = {
remoteAddr: { remoteAddr: {
transport: "tcp", transport: "tcp",
hostname: "127.0.0.1", hostname: "127.0.0.1",
+2 -1
View File
@@ -15,7 +15,8 @@ const router = (req: Request) => {
hostname: "127.0.0.1", hostname: "127.0.0.1",
port: 80, port: 80,
}, },
}); // deno-lint-ignore no-explicit-any
} as any);
}; };
Deno.test("forwards slash placed at the end of url", async () => { Deno.test("forwards slash placed at the end of url", async () => {