/// import { sleep } from "https://deno.land/x/sleep/mod.ts"; import { HttpCode, httpCodes } from "./http-codes.ts"; import { ContentType, contentTypes } from "./content-types.ts"; import { services } from "./services.ts"; import { DenoRequest, Handler, Method, ProcessedRoute, Request, Response, Route, UserRequest, } from "./types.ts"; const phandler: Handler = async (_req: Request) => { const code = httpCodes.success.OK; return { code, result: "it is ok ", contentType: contentTypes.text.plain, }; }; // FIXME: Obviously put this somewhere else const okText = (out: string) => { const code = httpCodes.success.OK; return { code, result: out, contentType: contentTypes.text.plain, }; }; const routes: Route[] = [ { path: "/slow", methods: ["get"], handler: async (_req) => { console.log("starting slow request"); await sleep(10); console.log("finishing slow request"); return okText("that was slow"); }, }, { path: "/list", methods: ["get"], handler: async (_req) => { const code = httpCodes.success.OK; const lr = (rr: Route[]) => { const ret = rr.map((r: Route) => { return r.path; }); return ret; }; const listing = lr(routes).join(", "); return { code, result: listing + "\n", contentType: contentTypes.text.plain, }; }, }, { path: "/ok", methods: ["get"], handler: async (_req) => { const code = httpCodes.success.OK; const rn = services.random.randomNumber(); return { code, result: "it is ok " + rn, contentType: contentTypes.text.plain, }; }, }, { path: "/alsook", methods: ["get"], handler: async (_req) => { const code = httpCodes.success.OK; return { code, result: "it is also ok", contentType: contentTypes.text.plain, }; }, }, ]; export { routes };