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 = {
|
export type HttpCode = {
|
||||||
code: number;
|
code: number;
|
||||||
@@ -11,8 +11,10 @@ type CodeDefinitions = {
|
|||||||
[K: string]: HttpCode;
|
[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: {
|
success: {
|
||||||
OK: { code: 200, name: "OK", "description": "" },
|
OK: { code: 200, name: "OK", "description": "" },
|
||||||
Created: { code: 201, name: "Created" },
|
Created: { code: 201, name: "Created" },
|
||||||
|
|||||||
@@ -3,14 +3,20 @@
|
|||||||
import { sleep } from "https://deno.land/x/sleep/mod.ts";
|
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";
|
import { ContentType, contentTypes } from "./content-types.ts";
|
||||||
import { services } from "./services";
|
import { services } from "./services.ts";
|
||||||
import {DenoRequest, Handler, Response, Method, UserRequest, Request, Route, ProcessedRoute } from './types.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;
|
const code = httpCodes.success.OK;
|
||||||
return {
|
return {
|
||||||
code,
|
code,
|
||||||
@@ -19,8 +25,6 @@ const phandler: Handler = async (req: Request) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// FIXME: Obviously put this somewhere else
|
// FIXME: Obviously put this somewhere else
|
||||||
const okText = (out: string) => {
|
const okText = (out: string) => {
|
||||||
const code = httpCodes.success.OK;
|
const code = httpCodes.success.OK;
|
||||||
@@ -39,7 +43,8 @@ const routes: Route[] = [
|
|||||||
handler: async (_req) => {
|
handler: async (_req) => {
|
||||||
console.log("starting slow request");
|
console.log("starting slow request");
|
||||||
await sleep(10);
|
await sleep(10);
|
||||||
console.log("finishing slow request"); return okText("that was slow");
|
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 { randomNumber } from "https://deno.land/x/random_number/mod.ts";
|
||||||
import { config } from "./config.ts";
|
import { config } from "./config.ts";
|
||||||
import { getLogs, log } from "./logging";
|
import { getLogs, log } from "./logging.ts";
|
||||||
|
|
||||||
|
|
||||||
//const database = Client({
|
//const database = Client({
|
||||||
|
|||||||
@@ -3,15 +3,28 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
|
import { z } from "zod";
|
||||||
import { HttpCode, httpCodes } from "./http-codes.ts";
|
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 DenoRequest = globalThis.Request;
|
||||||
|
export type DenoResponse=globalThis.Response;
|
||||||
export type UserRequest = {};
|
export type UserRequest = {};
|
||||||
export type Request = {
|
export type Request = {
|
||||||
pattern: string;
|
pattern: string;
|
||||||
@@ -20,9 +33,11 @@ export type Request = {
|
|||||||
parameters: object;
|
parameters: object;
|
||||||
denoRequest: globalThis.Request;
|
denoRequest: globalThis.Request;
|
||||||
};
|
};
|
||||||
export type ProcessedRoute = { pattern: URLPattern; method: Method; handler: Handler };
|
export type ProcessedRoute = {
|
||||||
|
pattern: URLPattern;
|
||||||
|
method: Method;
|
||||||
|
handler: Handler;
|
||||||
|
};
|
||||||
|
|
||||||
export type Response = {
|
export type Response = {
|
||||||
code: HttpCode;
|
code: HttpCode;
|
||||||
@@ -36,5 +51,7 @@ export type Route = {
|
|||||||
path: string;
|
path: string;
|
||||||
methods: Method[];
|
methods: Method[];
|
||||||
handler: Handler;
|
handler: Handler;
|
||||||
interruptable?: boolean
|
interruptable?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export { massageMethod };
|
||||||
|
|||||||
Reference in New Issue
Block a user