From d2938ce6fe52695ac379f0a466dbaec6be3a7f88 Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sat, 22 Jul 2023 10:08:53 -0400 Subject: [PATCH 1/7] obscure double-undescore routes --- run-serve.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/run-serve.tsx b/run-serve.tsx index 55ff51f..1e70e5c 100644 --- a/run-serve.tsx +++ b/run-serve.tsx @@ -270,10 +270,9 @@ const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(r const ext = Extension(url.pathname); const headers = {"content-type":"application/json", "Access-Control-Allow-Origin": Configuration.Allow, "charset":"UTF-8"}; - // cache-reset route - if(url.pathname === Configuration.Reset) + if(url.pathname.includes("/__")) { - return new Response(`{"cleared":${Transpile.Clear()}}`, {headers}); + return new Response(`{"error":"unmatched route", "path":"${url.pathname}"}`, {status:404, headers}); } // allow for custom handler @@ -335,6 +334,12 @@ const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(r } } + // cache-reset route + if(url.pathname === Configuration.Reset) + { + return new Response(`{"cleared":${Transpile.Clear()}}`, {headers}); + } + // all other static files if(ext) { From 2b59bd33aafd8292dde3c4ba82b30bfc578c9b0d Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sat, 29 Jul 2023 13:57:44 -0400 Subject: [PATCH 2/7] add proxy imports! remove file.deno.tsx falback --- deno.json | 4 ++- run-local.tsx | 17 ++--------- run-serve.tsx | 79 +++++++++++++++++++++++---------------------------- 3 files changed, 41 insertions(+), 59 deletions(-) diff --git a/deno.json b/deno.json index 61c231c..1de4cfe 100644 --- a/deno.json +++ b/deno.json @@ -7,7 +7,9 @@ { "react":"https://esm.sh/preact@10.15.1/compat", "react-original":"https://esm.sh/preact@10.15.1/compat", - "able/": "http://localhost:1234/" + "able/": "http://localhost:1234/", + "able:app": "./example/app.tsx", + ">able/": "https://gitea.hptrow.me/SethTrowbridge/able-baker/raw/branch/master/" }, "tasks": { diff --git a/run-local.tsx b/run-local.tsx index b1b1943..bae8e0d 100644 --- a/run-local.tsx +++ b/run-local.tsx @@ -1,4 +1,4 @@ -import {Configure, Transpile, Extension} from "./run-serve.tsx"; +import {Configure, Transpile, Extension, Root} from "./run-serve.tsx"; import * as Collect from "./hmr-static.tsx"; const SocketsLive:Set = new Set(); @@ -30,21 +30,8 @@ Configure({ if(Transpile.Check(inExt) && !inURL.searchParams.get("reload")) { -// const imp = await import(inConfig.Proxy+inURL.pathname); -// const members = []; -// for( const key in imp ) { members.push(key); } -// -// const code =` -//import {FileListen} from "${import.meta.resolve(`./hmr-listen.tsx`)}"; -//import * as Import from "${inURL.pathname}?reload=0"; -//${ members.map(m=>`let proxy_${m} = Import.${m}; export { proxy_${m} as ${m} };`).join("\n") } -//FileListen("${inURL.pathname}", (updatedModule)=> -//{ -// ${ members.map(m=>`proxy_${m} = updatedModule.${m};`).join("\n") } -//});` - // we dont need to add ?reload= because this fetch is by way the file system not the hosted url - const [local, foreign] = await Collect.FileExports(inConfig.Proxy+inURL.pathname); + const [local, foreign] = await Collect.FileExports(Root+inURL.pathname); const code =` import {FileListen} from "${import.meta.resolve(`./hmr-listen.tsx`)}"; import * as Import from "${inURL.pathname}?reload=0"; diff --git a/run-serve.tsx b/run-serve.tsx index 1e70e5c..21940f5 100644 --- a/run-serve.tsx +++ b/run-serve.tsx @@ -1,6 +1,7 @@ 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"; +export const Root = new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString(); Deno.args.forEach(arg=> { @@ -14,10 +15,11 @@ Deno.args.forEach(arg=> type DenoConfig = {imports:Record}; const ImportMap:DenoConfig = {imports:{}}; let ImportMapOriginal = {}; +let ImportMapProxies:Record = {}; const ImportMapReload =async()=> { let json:DenoConfig; - const path = Configuration.Proxy+"/deno.json"; + const path = Root+"/deno.json"; try { const resp = await fetch(path); @@ -41,17 +43,24 @@ const ImportMapReload =async()=> json.imports["react/"] = json.imports["react"]+"/"; } - if(!json.imports["entry"]) + if(!json.imports["able:app"]) { - console.log(`"entry" specifier not defined in import map.`); + console.log(`"able:app" specifier not defined in import map.`); } + + ImportMapProxies = {}; Object.entries(json.imports).forEach(([key, value])=> { if(value.startsWith("./")) { json.imports[key] = value.substring(1); } + if(key.startsWith(">")||key.startsWith("able/")) + { + ImportMapProxies["/"+encodeURI(key)] = value; + json.imports[key] = "/"+key; + } }); ImportMap.imports = Configuration.Remap(json.imports, Configuration); @@ -59,11 +68,10 @@ const ImportMapReload =async()=> type CustomHTTPHandler = (inReq:Request, inURL:URL, inExt:string|false, inMap:{imports:Record}, inConfig:Configuration)=>void|false|Response|Promise; type CustomRemapper = (inImports:Record, inConfig:Configuration)=>Record; -type Configuration = {Proxy:string, Allow:string, Reset:string, SWCOp:SWCW.Options, Serve:CustomHTTPHandler, Shell:CustomHTTPHandler, Remap:CustomRemapper}; -type ConfigurationArgs = {Proxy?:string, Allow?:string, Reset?:string, SWCOp?:SWCW.Options, Serve?:CustomHTTPHandler, Shell?:CustomHTTPHandler, Remap?:CustomRemapper}; +type Configuration = {Allow:string, Reset:string, SWCOp:SWCW.Options, Serve:CustomHTTPHandler, Shell:CustomHTTPHandler, Remap:CustomRemapper}; +type ConfigurationArgs = {Allow?:string, Reset?:string, SWCOp?:SWCW.Options, Serve?:CustomHTTPHandler, Shell?:CustomHTTPHandler, Remap?:CustomRemapper}; let Configuration:Configuration = { - Proxy: new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString(), Allow: "*", Reset: "/clear-cache", async Serve(inReq, inURL, inExt, inMap, inConfig){}, @@ -73,8 +81,6 @@ let Configuration:Configuration = }, Shell(inReq, inURL, inExt, inMap, inConfig) { - const parts = Deno.mainModule.split(inConfig.Proxy); - return new Response( ` @@ -87,7 +93,7 @@ let Configuration:Configuration = `, {status:200, headers:{"content-type":"text/html"}}); @@ -133,6 +139,7 @@ export const Transpile = return size; }, /** + * DONT USE * Converts dynamic module imports in to static, also can resolve paths with an import map */ async Patch(inPath:string, inKey:string, inMap?:DenoConfig) @@ -269,12 +276,30 @@ const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(r const url:URL = new URL(req.url); const ext = Extension(url.pathname); const headers = {"content-type":"application/json", "Access-Control-Allow-Origin": Configuration.Allow, "charset":"UTF-8"}; + let proxy = Root + url.pathname; if(url.pathname.includes("/__")) { return new Response(`{"error":"unmatched route", "path":"${url.pathname}"}`, {status:404, headers}); } + // proxy imports + if(url.pathname.startsWith(encodeURI("/>"))) + { + let bestMatch=""; + for(let key in ImportMapProxies) + { + if(url.pathname.startsWith(key) && key.length > bestMatch.length) + { + bestMatch = key; + } + } + if(bestMatch.length) + { + proxy = ImportMapProxies[bestMatch] + url.pathname.substring(bestMatch.length); + } + } + // allow for custom handler const custom = await Configuration.Serve(req, url, ext, ImportMap, Configuration); if(custom) @@ -285,39 +310,7 @@ const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(r // transpileable files if(Transpile.Check(ext)) { - let code; - let path; - let file; - if( req.headers.get("user-agent")?.startsWith("Deno") || url.searchParams.has("deno") ) - { - try - { - path = Configuration.Proxy + ExtensionPrefix(url.pathname, "deno"); - console.log("looking for", path); - file = await fetch(path) as Response; - if(file.ok) - { - code = await file.text(); - } - else - { - throw new Error("404"); - } - } - catch(e) - { - path = Configuration.Proxy + url.pathname; - console.log("falling back to", path); - file = await fetch(path); - code = await file.text(); - } - } - else - { - path = Configuration.Proxy + url.pathname; - code = await Transpile.Fetch(path, url.pathname); - } - + const code = await Transpile.Fetch(proxy, url.pathname); if(code) { return new Response(code, {headers:{...headers, "content-type":"application/javascript"}} ); @@ -346,7 +339,7 @@ const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(r try { const type = MIME.typeByExtension(ext); - const file = await fetch(Configuration.Proxy + url.pathname); + const file = await fetch(proxy); return new Response(file.body, {headers:{...headers, "content-type":type||""}}); } catch(e) From 254cd45a2c5bf1f19160f5b5d50163fa1309750b Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sat, 29 Jul 2023 16:45:41 -0400 Subject: [PATCH 3/7] fix hmr, modify example --- api.tsx | 1 + app.tsx | 1 + deno.json | 2 -- example/app.tsx | 4 +-- example/deno.json | 8 ++--- example/dyn-test.tsx | 15 --------- run-local.tsx | 73 +++++++++++++++++++++++++------------------- run-serve.tsx | 27 +++++++++++----- 8 files changed, 70 insertions(+), 61 deletions(-) create mode 100644 api.tsx create mode 100644 app.tsx delete mode 100644 example/dyn-test.tsx diff --git a/api.tsx b/api.tsx new file mode 100644 index 0000000..2308168 --- /dev/null +++ b/api.tsx @@ -0,0 +1 @@ +export default ()=>{}; \ No newline at end of file diff --git a/app.tsx b/app.tsx new file mode 100644 index 0000000..2308168 --- /dev/null +++ b/app.tsx @@ -0,0 +1 @@ +export default ()=>{}; \ No newline at end of file diff --git a/deno.json b/deno.json index 1de4cfe..0c02170 100644 --- a/deno.json +++ b/deno.json @@ -7,8 +7,6 @@ { "react":"https://esm.sh/preact@10.15.1/compat", "react-original":"https://esm.sh/preact@10.15.1/compat", - "able/": "http://localhost:1234/", - "able:app": "./example/app.tsx", ">able/": "https://gitea.hptrow.me/SethTrowbridge/able-baker/raw/branch/master/" }, "tasks": diff --git a/example/app.tsx b/example/app.tsx index 0f99425..e2f7de8 100644 --- a/example/app.tsx +++ b/example/app.tsx @@ -1,4 +1,4 @@ -import { Router, Switch, Case } from "able/iso-elements.tsx"; +import { Router, Switch, Case } from ">able/iso-elements.tsx"; import React from "react"; @@ -39,7 +39,7 @@ export default ()=> return
-

Title

+

Title?????

subtitle

diff --git a/example/deno.json b/example/deno.json index a352b2f..0b248ee 100644 --- a/example/deno.json +++ b/example/deno.json @@ -3,12 +3,12 @@ "imports": { "react": "https://esm.sh/preact@10.15.1/compat", - "able/": "http://localhost:1234/", - "entry": "./app.tsx" + ">able/app.tsx": "./app.tsx", + ">able/": "http://localhost:4507/" }, "tasks": { - "local": "deno run -A --no-lock --reload=http://localhost:1234 http://localhost:1234/run-local.tsx", - "serve": "deno run -A --no-lock --reload=http://localhost:1234 http://localhost:1234/run-serve.tsx" + "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" } } \ No newline at end of file diff --git a/example/dyn-test.tsx b/example/dyn-test.tsx deleted file mode 100644 index 63ca671..0000000 --- a/example/dyn-test.tsx +++ /dev/null @@ -1,15 +0,0 @@ - -import * as Util from "@able/"; -import * as React from "react"; -import {createElement} from "react/client"; - -import('react').then((module) => { - console.log(module); -}); - - -function unimport(n:number) -{ - return n; -} -unimport(123) \ No newline at end of file diff --git a/run-local.tsx b/run-local.tsx index bae8e0d..e76ed3a 100644 --- a/run-local.tsx +++ b/run-local.tsx @@ -22,44 +22,55 @@ Configure({ Remap: (inImports, inConfig)=> { inImports["react-original"] = inImports["react"]; - inImports["react"] = import.meta.resolve(`./hmr-react.tsx`); + inImports["react"] = `/>able/hmr-react.tsx`; return inImports; }, async Serve(inReq, inURL, inExt, inMap, inConfig) { - if(Transpile.Check(inExt) && !inURL.searchParams.get("reload")) + if(!inURL.pathname.startsWith(encodeURI("/>"))) { - - // we dont need to add ?reload= because this fetch is by way the file system not the hosted url - const [local, foreign] = await Collect.FileExports(Root+inURL.pathname); - const code =` -import {FileListen} from "${import.meta.resolve(`./hmr-listen.tsx`)}"; -import * as Import from "${inURL.pathname}?reload=0"; -${ local.map(m=>`let proxy_${m} = Import.${m}; export { proxy_${m} as ${m} };`).join("\n") } -FileListen("${inURL.pathname}", (updatedModule)=> -{ - ${ local.map(m=>`proxy_${m} = updatedModule.${m};`).join("\n") } -}); -${ foreign.join(";\n") } -` - - return new Response(code, {headers:{"content-type":"application/javascript"}}); - } - - - if(inReq.headers.get("upgrade") == "websocket") - { - try + if(Transpile.Check(inExt) && !inURL.searchParams.get("reload")) { - const { response, socket } = Deno.upgradeWebSocket(inReq); - socket.onopen = () => SocketsLive.add(socket); - socket.onclose = () => SocketsLive.delete(socket); - socket.onmessage = (e) => {}; - socket.onerror = (e) => console.log("Socket errored:", e); - return response; + + // we dont need to add ?reload= because this fetch is by way the file system not the hosted url + + console.log("collecting exports for", Root+inURL.pathname); + + const [local, foreign] = await Collect.FileExports(Root+inURL.pathname); + const code =` + import {FileListen} from ">able/hmr-listen.tsx"; + import * as Import from "${inURL.pathname}?reload=0"; + ${ local.map(m=>`let proxy_${m} = Import.${m}; export { proxy_${m} as ${m} };`).join("\n") } + FileListen("${inURL.pathname}", (updatedModule)=> + { + ${ local.map(m=>`proxy_${m} = updatedModule.${m};`).join("\n") } + }); + ${ foreign.join(";\n") } + ` + + return new Response(code, {headers:{"content-type":"application/javascript"}}); } - catch(e){ /**/ } + + + if(inReq.headers.get("upgrade") == "websocket") + { + try + { + const { response, socket } = Deno.upgradeWebSocket(inReq); + socket.onopen = () => SocketsLive.add(socket); + socket.onclose = () => SocketsLive.delete(socket); + socket.onmessage = (e) => {}; + socket.onerror = (e) => console.log("Socket errored:", e); + return response; + } + catch(e){ /**/ } + } } + else + { + console.log("not collecting", inURL.pathname) + } + } }); @@ -82,7 +93,7 @@ const Watcher =async()=> const key = path.substring(Deno.cwd().length).replaceAll("\\", "/"); if(action != "remove") { - const tsx = await Transpile.Fetch(`file://${Deno.cwd().replaceAll("\\", "/")}`+key, key, true); + const tsx = await Transpile.Fetch(Root+key, key, true); tsx && SocketsSend(key); } else diff --git a/run-serve.tsx b/run-serve.tsx index 21940f5..831a99b 100644 --- a/run-serve.tsx +++ b/run-serve.tsx @@ -56,10 +56,18 @@ const ImportMapReload =async()=> { json.imports[key] = value.substring(1); } - if(key.startsWith(">")||key.startsWith("able/")) + if(key.startsWith(">")) { - ImportMapProxies["/"+encodeURI(key)] = value; - json.imports[key] = "/"+key; + if(value.startsWith("./")) + { + ImportMapProxies[encodeURI(key)] = value.substring(1); + json.imports[key] = value.substring(1); + } + else + { + ImportMapProxies["/"+encodeURI(key)] = value; + json.imports[key] = "/"+key; + } } }); @@ -92,8 +100,8 @@ let Configuration:Configuration =

`, {status:200, headers:{"content-type":"text/html"}}); @@ -296,9 +304,13 @@ const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(r } if(bestMatch.length) { - proxy = ImportMapProxies[bestMatch] + url.pathname.substring(bestMatch.length); - } + const match = ImportMapProxies[bestMatch]; + const path = url.pathname.substring(bestMatch.length); + proxy = path ? match + path : Root + match; + + } } + console.log("proxy will be", proxy); // allow for custom handler const custom = await Configuration.Serve(req, url, ext, ImportMap, Configuration); @@ -310,6 +322,7 @@ const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(r // transpileable files if(Transpile.Check(ext)) { + console.log("transpiling:", proxy); const code = await Transpile.Fetch(proxy, url.pathname); if(code) { From b118ba02f93a75212c630be7c5237ae5393b0afd Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sat, 29 Jul 2023 17:13:49 -0400 Subject: [PATCH 4/7] setup debug --- .vscode/launch.json | 16 ++++++++++++++++ .vscode/settings.json | 3 +-- deno.json | 3 ++- run-local.tsx | 7 ------- run-serve.tsx | 14 ++++++++++++-- 5 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..33b5a41 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "request": "launch", + "name": "Debug Serve Mode", + "type": "node", + "runtimeExecutable": "deno", + "runtimeArgs": ["task", "debug"], + "attachSimplePort": 9229 + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index b003be2..8675ad5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,4 @@ { "deno.enable": true, - "deno.unstable": true, - "deno.config": "./deno.json" + "deno.unstable": true } \ No newline at end of file diff --git a/deno.json b/deno.json index 0c02170..3aa3101 100644 --- a/deno.json +++ b/deno.json @@ -12,6 +12,7 @@ "tasks": { "local": "deno run -A --no-lock ./run-local.tsx --port=1234", - "serve": "deno run -A --no-lock ./run-serve.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" } } \ No newline at end of file diff --git a/run-local.tsx b/run-local.tsx index e76ed3a..6cf1af7 100644 --- a/run-local.tsx +++ b/run-local.tsx @@ -33,9 +33,6 @@ Configure({ { // we dont need to add ?reload= because this fetch is by way the file system not the hosted url - - console.log("collecting exports for", Root+inURL.pathname); - const [local, foreign] = await Collect.FileExports(Root+inURL.pathname); const code =` import {FileListen} from ">able/hmr-listen.tsx"; @@ -66,10 +63,6 @@ Configure({ catch(e){ /**/ } } } - else - { - console.log("not collecting", inURL.pathname) - } } }); diff --git a/run-serve.tsx b/run-serve.tsx index 831a99b..ea500b6 100644 --- a/run-serve.tsx +++ b/run-serve.tsx @@ -278,7 +278,16 @@ export const Configure =(config:ConfigurationArgs)=> } await ImportMapReload(); -await SWCW.default(); +try +{ + await SWCW.default(); +} +catch(e) +{ + console.log("swc init error:", e); +} + + const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(req: Request)=> { const url:URL = new URL(req.url); @@ -363,4 +372,5 @@ const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(r return new Response(`{"error":"unmatched route", "path":"${url.pathname}"}`, {status:404, headers}); -}); \ No newline at end of file +}); + From 6cee7ac0654cba5737499c619bdc25f03dd708db Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sat, 29 Jul 2023 18:21:59 -0400 Subject: [PATCH 5/7] 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)) { From 06981cc067f851f7145e75b14869182b064abf0c Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sat, 29 Jul 2023 18:49:44 -0400 Subject: [PATCH 6/7] fix path (no ext) --- run-serve.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-serve.tsx b/run-serve.tsx index 3194d42..73a748f 100644 --- a/run-serve.tsx +++ b/run-serve.tsx @@ -104,7 +104,7 @@ let Configuration:Configuration = `, {status:200, headers:{"content-type":"text/html"}}); From 19097e1e6841019e059519ae9e424c2a57917f1f Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sat, 29 Jul 2023 20:25:41 -0400 Subject: [PATCH 7/7] tweak deploy script --- deno.json | 3 ++- example/.env | 1 + run-deploy.tsx | 13 ++++--------- 3 files changed, 7 insertions(+), 10 deletions(-) create mode 100644 example/.env diff --git a/deno.json b/deno.json index 68782be..f8d9679 100644 --- a/deno.json +++ b/deno.json @@ -13,6 +13,7 @@ { "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" + "debug": "deno run -A --reload=http://localhost --inspect-wait --no-lock ./run-serve.tsx --port=1234", + "deploy":"deno run -A --no-lock --reload=http://localhost http://localhost:4507/run-deploy.tsx" } } \ No newline at end of file diff --git a/example/.env b/example/.env new file mode 100644 index 0000000..6a7678a --- /dev/null +++ b/example/.env @@ -0,0 +1 @@ +DENO_DEPLOY_TOKEN=1 \ No newline at end of file diff --git a/run-deploy.tsx b/run-deploy.tsx index 37d7961..89af979 100644 --- a/run-deploy.tsx +++ b/run-deploy.tsx @@ -1,4 +1,4 @@ -import { load } from "https://deno.land/std@0.194.0/dotenv/mod.ts"; +import * as Env from "https://deno.land/std@0.194.0/dotenv/mod.ts"; import { parse } from "https://deno.land/std@0.194.0/flags/mod.ts"; @@ -47,18 +47,12 @@ try { console.log("Runing deploy!"); const serveScript = import.meta.resolve("./run-serve.tsx"); - console.log("Serve script:", serveScript); let arg = parse(Deno.args); - let env = await load(); + let env = await Env.load(); let useToken = await collect("DENO_DEPLOY_TOKEN", arg, env); let useProject = await collect("DENO_DEPLOY_PROJECT", arg, env); - let useEntry = await collect("DENO_DEPLOY_ENTRY", arg, env); - - Deno.env.set("DENO_DEPLOY_TOKEN", useToken || ""); - Deno.env.set("DENO_DEPLOY_ENTRY", useEntry || ""); - const command = new Deno.Command( `deno`, @@ -67,10 +61,11 @@ try "run", "-A", "--no-lock", - "--config=deno.json", "https://deno.land/x/deploy/deployctl.ts", "deploy", `--project=${useProject}`, + `--config=deno.json`, + `--token=${useToken}`, serveScript ], stdin: "piped",