Compare commits
2 Commits
72284505a0
...
235d2b50dd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
235d2b50dd | ||
|
|
553cd680dc |
19
deno/handlers.ts
Normal file
19
deno/handlers.ts
Normal 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 };
|
||||||
@@ -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",
|
||||||
|
|||||||
@@ -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";
|
||||||
|
|||||||
Reference in New Issue
Block a user