2 Commits

Author SHA1 Message Date
Michael Wolf
235d2b50dd Add a FIXME 2025-03-07 21:46:33 -06:00
Michael Wolf
553cd680dc Move handler into a different file 2025-03-07 21:46:19 -06:00
3 changed files with 25 additions and 10 deletions

19
deno/handlers.ts Normal file
View File

@@ -0,0 +1,19 @@
import { contentTypes } from "./content-types.ts";
import { httpCodes } from "./http-codes.ts";
import { services } from "./services.ts";
import { Request,Handler, Response } from "./types.ts";
const multiHandler: Handler = (req: Request): Response => {
const code = httpCodes.success.OK;
const rn = services.random.randomNumber();
const retval: Response = {
code,
result: `that was ${req.method} (${rn})`,
contentType: contentTypes.text.plain,
};
return retval;
};
export { multiHandler };

View File

@@ -5,6 +5,7 @@ import { sleep } from "https://deno.land/x/sleep/mod.ts";
import { HttpCode, httpCodes } from "./http-codes.ts"; import { HttpCode, httpCodes } from "./http-codes.ts";
import { ContentType, contentTypes } from "./content-types.ts"; import { ContentType, contentTypes } from "./content-types.ts";
import { services } from "./services.ts"; import { services } from "./services.ts";
import { multiHandler } from "./handlers.ts";
import { import {
DenoRequest, DenoRequest,
Handler, Handler,
@@ -62,16 +63,7 @@ const routes: Route[] = [
{ {
path: "/ok", path: "/ok",
methods: ["GET", "POST", "PUT"], methods: ["GET", "POST", "PUT"],
handler: (req: Request) => { handler: multiHandler,
const code = httpCodes.success.OK;
const rn = services.random.randomNumber();
return {
code,
result: `that was ${req.method} (${rn})`,
contentType: contentTypes.text.plain,
};
},
}, },
{ {
path: "/alsook", path: "/alsook",

View File

@@ -3,6 +3,10 @@
// FIXME: split this up into types used by app developers and types internal // FIXME: split this up into types used by app developers and types internal
// to the framework. // to the framework.
// FIXME: the use of types like Request and Response cause problems because it's
// easy to forget to import them and then all sorts of random typechecking errors
// start showing up even if the code is sound. So find other names for them.
import { z } from "zod"; import { z } from "zod";
import { HttpCode, httpCodes } from "./http-codes.ts"; import { HttpCode, httpCodes } from "./http-codes.ts";
import { ContentType, contentTypes } from "./content-types.ts"; import { ContentType, contentTypes } from "./content-types.ts";