Skip to content

Commit

Permalink
fix: ServerhandlerInfo type for newer Deno versions
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed May 2, 2024
1 parent bc75101 commit 0fefc50
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
21 changes: 12 additions & 9 deletions src/server/boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,18 @@ async function bootServer(
// @ts-ignore Ignore type error when type checking with Deno versions
await Deno.serve(
opts,
(r, { remoteAddr }) =>
handler(r, {
remoteAddr,
localAddr: {
transport: "tcp",
hostname: opts.hostname ?? "localhost",
port: opts.port,
} as Deno.NetAddr,
}),
(r, info) =>
handler(
r,
{
...info,
localAddr: {
transport: "tcp",
hostname: opts.hostname ?? "localhost",
port: opts.port,
} as Deno.NetAddr,
},
),
).finished;
} else {
// @ts-ignore Deprecated std serve way
Expand Down
4 changes: 3 additions & 1 deletion src/server/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ import { withBase } from "./router.ts";
import { PARTIAL_SEARCH_PARAM } from "../constants.ts";
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 },
remoteAddr: { transport: "tcp", hostname: "localhost", port: 1234 },
};
Expand Down
3 changes: 1 addition & 2 deletions src/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,12 @@ export interface RouteConfig {

export interface RenderOptions extends ResponseInit {}

export type ServeHandlerInfo = {
export type ServeHandlerInfo = Deno.ServeHandlerInfo & {
/**
* Backwards compatible with std/server
* @deprecated
*/
localAddr?: Deno.NetAddr;
remoteAddr: Deno.NetAddr;
};

export type ServeHandler = (
Expand Down

0 comments on commit 0fefc50

Please sign in to comment.