fix: change MultiHandler back to Handlers (#1396)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { MultiHandler } from "../../../server.ts";
|
||||
import { Handlers } from "../../../server.ts";
|
||||
|
||||
export const handler: MultiHandler = {
|
||||
export const handler: Handlers = {
|
||||
GET(_req, ctx) {
|
||||
return new Response((ctx.remoteAddr as Deno.NetAddr).hostname);
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MultiHandler, PageProps } from "$fresh/server.ts";
|
||||
import { Handlers, PageProps } from "$fresh/server.ts";
|
||||
|
||||
interface Data extends Record<string, unknown> {
|
||||
info: string;
|
||||
@@ -8,7 +8,7 @@ export default function Page({ data }: PageProps<Data>) {
|
||||
return <div>{data.info}</div>;
|
||||
}
|
||||
|
||||
export const handler: MultiHandler<Data> = {
|
||||
export const handler: Handlers<Data> = {
|
||||
GET(req, { render }) {
|
||||
if (req.headers.get("accept")?.includes("text/html")) {
|
||||
return render({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MultiHandler } from "../../../../../server.ts";
|
||||
import { Handlers } from "../../../../../server.ts";
|
||||
|
||||
interface State {
|
||||
root: string;
|
||||
@@ -6,7 +6,7 @@ interface State {
|
||||
layer3: string;
|
||||
}
|
||||
|
||||
export const handler: MultiHandler<undefined, State> = {
|
||||
export const handler: Handlers<undefined, State> = {
|
||||
GET(_req: Request, { state }) {
|
||||
return new Response(JSON.stringify(state));
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MultiHandler } from "../../../../../server.ts";
|
||||
import { Handlers } from "../../../../../server.ts";
|
||||
|
||||
interface State {
|
||||
root: string;
|
||||
@@ -6,7 +6,7 @@ interface State {
|
||||
layer2: string;
|
||||
}
|
||||
|
||||
export const handler: MultiHandler<undefined, State> = {
|
||||
export const handler: Handlers<undefined, State> = {
|
||||
GET(_req: Request, { state }) {
|
||||
return new Response(JSON.stringify(state));
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MultiHandler } from "../../../../../server.ts";
|
||||
import { Handlers } from "../../../../../server.ts";
|
||||
|
||||
interface State {
|
||||
root: string;
|
||||
@@ -6,7 +6,7 @@ interface State {
|
||||
layer2: string;
|
||||
}
|
||||
|
||||
export const handler: MultiHandler<undefined, State> = {
|
||||
export const handler: Handlers<undefined, State> = {
|
||||
GET(_req: Request, { state }) {
|
||||
return new Response(JSON.stringify(state));
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { MultiHandler } from "../../../../../../server.ts";
|
||||
import { Handlers } from "../../../../../../server.ts";
|
||||
|
||||
interface State {
|
||||
root: string;
|
||||
@@ -7,7 +7,7 @@ interface State {
|
||||
layer3: string;
|
||||
}
|
||||
|
||||
export const handler: MultiHandler<undefined, State> = {
|
||||
export const handler: Handlers<undefined, State> = {
|
||||
GET(_req: Request, { state }) {
|
||||
return new Response(JSON.stringify(state));
|
||||
},
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { MultiHandler } from "../../../server.ts";
|
||||
import { Handlers } from "../../../server.ts";
|
||||
|
||||
interface State {
|
||||
root: string;
|
||||
}
|
||||
|
||||
export const handler: MultiHandler<undefined, State> = {
|
||||
export const handler: Handlers<undefined, State> = {
|
||||
GET(_req: Request, { state }) {
|
||||
return new Response(JSON.stringify(state));
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { MultiHandler } from "../../../server.ts";
|
||||
import { Handlers } from "../../../server.ts";
|
||||
|
||||
export const handler: MultiHandler = {
|
||||
export const handler: Handlers = {
|
||||
GET(_req, ctx) {
|
||||
return ctx.renderNotFound({
|
||||
hello: "Dino",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { MultiHandler } from "../../../server.ts";
|
||||
import { Handlers } from "../../../server.ts";
|
||||
|
||||
export const handler: MultiHandler = {
|
||||
export const handler: Handlers = {
|
||||
GET(_req, ctx) {
|
||||
return new Response(ctx.params.all);
|
||||
},
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"lock": false,
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.1.0"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "preact"
|
||||
}
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env -S deno run -A --watch=static/,routes/
|
||||
|
||||
import dev from "$fresh/dev.ts";
|
||||
|
||||
await dev(import.meta.url, "./main.ts");
|
||||
@@ -0,0 +1,15 @@
|
||||
// DO NOT EDIT. This file is generated by fresh.
|
||||
// This file SHOULD be checked into source version control.
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import * as $0 from "./routes/index.tsx";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/index.tsx": $0,
|
||||
},
|
||||
islands: {},
|
||||
baseUrl: import.meta.url,
|
||||
};
|
||||
|
||||
export default manifest;
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
|
||||
import { start } from "$fresh/server.ts";
|
||||
import manifest from "./fresh.gen.ts";
|
||||
|
||||
await start(manifest);
|
||||
@@ -0,0 +1,7 @@
|
||||
import { Handlers } from "../../../server.ts";
|
||||
|
||||
export const handlers: Handlers = {
|
||||
GET() {
|
||||
throw new Error("FAIL");
|
||||
},
|
||||
};
|
||||
@@ -10,6 +10,7 @@ import manifest from "./fixture/fresh.gen.ts";
|
||||
import options from "./fixture/options.ts";
|
||||
import { BUILD_ID } from "../src/server/build_id.ts";
|
||||
import { startFreshServer } from "./test_utils.ts";
|
||||
import { assertMatch } from "https://deno.land/std@0.190.0/testing/asserts.ts";
|
||||
|
||||
const ctx = await ServerContext.fromManifest(manifest, options);
|
||||
const handler = ctx.handler();
|
||||
@@ -815,6 +816,22 @@ Deno.test("PORT environment variable", {
|
||||
serverProcess.kill("SIGTERM");
|
||||
});
|
||||
|
||||
Deno.test("throw on route export 'handlers' instead of 'handler'", {
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
}, async () => {
|
||||
const result = await new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "./tests/fixture_invalid_handlers/main.ts"],
|
||||
stderr: "piped",
|
||||
stdout: "piped",
|
||||
}).output();
|
||||
|
||||
assertEquals(result.code, 1);
|
||||
|
||||
const text = new TextDecoder().decode(result.stderr);
|
||||
assertMatch(text, /Did you mean "handler"\?/);
|
||||
});
|
||||
|
||||
Deno.test("rendering custom _500.tsx page for default handlers", {
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
|
||||
Reference in New Issue
Block a user