From 6cee7ac0654cba5737499c619bdc25f03dd708db Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sat, 29 Jul 2023 18:21:59 -0400 Subject: [PATCH] custom api handler started --- .vscode/launch.json | 1 + api | 4 ++++ api.tsx => app | 0 app.tsx | 1 - deno.json | 8 ++++---- example/api.tsx | 4 ++++ example/deno.json | 11 +++++++---- run-deploy.tsx | 1 + run-serve.tsx | 10 +++++++++- 9 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 api rename api.tsx => app (100%) delete mode 100644 app.tsx create mode 100644 example/api.tsx diff --git a/.vscode/launch.json b/.vscode/launch.json index 33b5a41..a00fbf1 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,6 +8,7 @@ "request": "launch", "name": "Debug Serve Mode", "type": "node", + "cwd": "${workspaceFolder}/example", "runtimeExecutable": "deno", "runtimeArgs": ["task", "debug"], "attachSimplePort": 9229 diff --git a/api b/api new file mode 100644 index 0000000..777ecae --- /dev/null +++ b/api @@ -0,0 +1,4 @@ +export default (req:Request):Response|false=> +{ + return false; +} \ No newline at end of file diff --git a/api.tsx b/app similarity index 100% rename from api.tsx rename to app diff --git a/app.tsx b/app.tsx deleted file mode 100644 index 2308168..0000000 --- a/app.tsx +++ /dev/null @@ -1 +0,0 @@ -export default ()=>{}; \ No newline at end of file diff --git a/deno.json b/deno.json index 3aa3101..68782be 100644 --- a/deno.json +++ b/deno.json @@ -7,12 +7,12 @@ { "react":"https://esm.sh/preact@10.15.1/compat", "react-original":"https://esm.sh/preact@10.15.1/compat", - ">able/": "https://gitea.hptrow.me/SethTrowbridge/able-baker/raw/branch/master/" + ">able/": "http://localhost:4507/" }, "tasks": { - "local": "deno run -A --no-lock ./run-local.tsx --port=1234", - "serve": "deno run -A --no-lock ./run-serve.tsx --port=1234", - "debug": "deno run -A --inspect-wait --no-lock ./run-serve.tsx --port=1234" + "local": "deno run -A --reload=http://localhost --no-lock ./run-local.tsx --port=1234", + "serve": "deno run -A --reload=http://localhost --no-lock ./run-serve.tsx --port=1234", + "debug": "deno run -A --reload=http://localhost --inspect-wait --no-lock ./run-serve.tsx --port=1234" } } \ No newline at end of file diff --git a/example/api.tsx b/example/api.tsx new file mode 100644 index 0000000..75d913f --- /dev/null +++ b/example/api.tsx @@ -0,0 +1,4 @@ +export default (inReq:Request)=> +{ + return false; +} \ No newline at end of file diff --git a/example/deno.json b/example/deno.json index 0b248ee..9155bc1 100644 --- a/example/deno.json +++ b/example/deno.json @@ -3,12 +3,15 @@ "imports": { "react": "https://esm.sh/preact@10.15.1/compat", - ">able/app.tsx": "./app.tsx", - ">able/": "http://localhost:4507/" + ">able/": "http://localhost:4507/", + ">able/app": "./app.tsx", + ">able/api": "./api.tsx" }, "tasks": { - "local": "deno run -A --no-lock --reload=http://localhost:4507/ http://localhost:4507/run-local.tsx", - "serve": "deno run -A --no-lock --reload=http://localhost:4507/ http://localhost:4507/run-serve.tsx" + "local": "deno run --config=deno.json -A --no-lock --reload=http://localhost:4507 http://localhost:4507/run-local.tsx", + "serve": "deno run --config=deno.json -A --no-lock --reload=http://localhost:4507 http://localhost:4507/run-serve.tsx", + "deploy":"deno run -A --no-lock --reload=http://localhost:4507 http://localhost:4507/run-deploy.tsx", + "debug": "deno run --config=deno.json -A --inspect-wait --no-lock --reload=http://localhost:4507 http://localhost:4507/run-serve.tsx" } } \ No newline at end of file diff --git a/run-deploy.tsx b/run-deploy.tsx index 478419c..37d7961 100644 --- a/run-deploy.tsx +++ b/run-deploy.tsx @@ -67,6 +67,7 @@ try "run", "-A", "--no-lock", + "--config=deno.json", "https://deno.land/x/deploy/deployctl.ts", "deploy", `--project=${useProject}`, diff --git a/run-serve.tsx b/run-serve.tsx index ea500b6..3194d42 100644 --- a/run-serve.tsx +++ b/run-serve.tsx @@ -1,6 +1,9 @@ import * as MIME from "https://deno.land/std@0.180.0/media_types/mod.ts"; import * as SWCW from "https://esm.sh/@swc/wasm-web@1.3.62"; +import Api from ">able/api"; + + export const Root = new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString(); Deno.args.forEach(arg=> @@ -319,7 +322,6 @@ const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(r } } - console.log("proxy will be", proxy); // allow for custom handler const custom = await Configuration.Serve(req, url, ext, ImportMap, Configuration); @@ -328,6 +330,12 @@ const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(r return custom; } + const api = Api(req); + if(api) + { + return api; + } + // transpileable files if(Transpile.Check(ext)) {