Compare commits
4 Commits
ad2b85bc2b
...
6d2779ba83
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d2779ba83 | ||
|
|
c19e6a9537 | ||
|
|
d48a533d42 | ||
|
|
d6fda3fdb3 |
@@ -1,4 +1,4 @@
|
||||
import { Extensible } from "./interfaces";
|
||||
import { Extensible } from "./interfaces.ts";
|
||||
|
||||
export type HttpCode = {
|
||||
code: number;
|
||||
@@ -11,8 +11,10 @@ type CodeDefinitions = {
|
||||
[K: string]: HttpCode;
|
||||
};
|
||||
};
|
||||
// FIXME: Figure out how to brand CodeDefinitions in a way that isn't
|
||||
// tedious.
|
||||
|
||||
const httpCodes: CodeDefinitions & Extensible = {
|
||||
const httpCodes: CodeDefinitions = {
|
||||
success: {
|
||||
OK: { code: 200, name: "OK", "description": "" },
|
||||
Created: { code: 201, name: "Created" },
|
||||
|
||||
@@ -3,14 +3,20 @@
|
||||
import { sleep } from "https://deno.land/x/sleep/mod.ts";
|
||||
|
||||
import { HttpCode, httpCodes } from "./http-codes.ts";
|
||||
import { ContentType, contentTypes } from "./content-types";
|
||||
import { services } from "./services";
|
||||
import {DenoRequest, Handler, Response, Method, UserRequest, Request, Route, ProcessedRoute } from './types.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 phandler: Handler = async (_req: Request) => {
|
||||
const code = httpCodes.success.OK;
|
||||
return {
|
||||
code,
|
||||
@@ -19,8 +25,6 @@ const phandler: Handler = async (req: Request) => {
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
// FIXME: Obviously put this somewhere else
|
||||
const okText = (out: string) => {
|
||||
const code = httpCodes.success.OK;
|
||||
@@ -37,9 +41,10 @@ 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");
|
||||
console.log("starting slow request");
|
||||
await sleep(10);
|
||||
console.log("finishing slow request");
|
||||
return okText("that was slow");
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -91,11 +96,4 @@ const routes: Route[] = [
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export {routes}
|
||||
export { routes };
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { randomNumber } from "https://deno.land/x/random_number/mod.ts";
|
||||
import { config } from "./config.ts";
|
||||
import { getLogs, log } from "./logging";
|
||||
import { getLogs, log } from "./logging.ts";
|
||||
|
||||
|
||||
//const database = Client({
|
||||
|
||||
@@ -3,15 +3,28 @@
|
||||
// FIXME: split this up into types used by app developers and types internal
|
||||
// to the framework.
|
||||
|
||||
|
||||
import { z } from "zod";
|
||||
import { HttpCode, httpCodes } from "./http-codes.ts";
|
||||
import { ContentType, contentTypes } from "./content-types";
|
||||
import { ContentType, contentTypes } from "./content-types.ts";
|
||||
|
||||
const methodParser = z.union([
|
||||
z.literal("get"),
|
||||
z.literal("post"),
|
||||
z.literal("put"),
|
||||
z.literal("patch"),
|
||||
z.literal("delete"),
|
||||
]);
|
||||
|
||||
export type Method = "get" | "post" | "put" | "patch" | "delete";
|
||||
export type Method = z.infer<typeof methodParser>;
|
||||
|
||||
const massageMethod = (input: string): Method => {
|
||||
const r = methodParser.parse(input.toLowerCase())
|
||||
|
||||
return r;
|
||||
};
|
||||
|
||||
export type DenoRequest = globalThis.Request;
|
||||
export type DenoResponse=globalThis.Response;
|
||||
export type UserRequest = {};
|
||||
export type Request = {
|
||||
pattern: string;
|
||||
@@ -20,9 +33,11 @@ export type Request = {
|
||||
parameters: object;
|
||||
denoRequest: globalThis.Request;
|
||||
};
|
||||
export type ProcessedRoute = { pattern: URLPattern; method: Method; handler: Handler };
|
||||
|
||||
|
||||
export type ProcessedRoute = {
|
||||
pattern: URLPattern;
|
||||
method: Method;
|
||||
handler: Handler;
|
||||
};
|
||||
|
||||
export type Response = {
|
||||
code: HttpCode;
|
||||
@@ -36,5 +51,7 @@ export type Route = {
|
||||
path: string;
|
||||
methods: Method[];
|
||||
handler: Handler;
|
||||
interruptable?: boolean
|
||||
interruptable?: boolean;
|
||||
};
|
||||
|
||||
export { massageMethod };
|
||||
|
||||
Reference in New Issue
Block a user