outpost relay mode started
This commit is contained in:
parent
66b148d7f5
commit
0ea5c3e562
@ -1,15 +0,0 @@
|
||||
import "./run-serve.tsx";
|
||||
|
||||
Deno.args.forEach(arg=>
|
||||
{
|
||||
if(arg.startsWith("--"))
|
||||
{
|
||||
const kvp = arg.substring(2).split("=");
|
||||
Deno.env.set(kvp[0], kvp[1] || "true");
|
||||
}
|
||||
});
|
||||
|
||||
if(Deno.env.get("dev"))
|
||||
{
|
||||
await import("./run-local.tsx");
|
||||
}
|
6
boot.deno.tsx
Normal file
6
boot.deno.tsx
Normal file
@ -0,0 +1,6 @@
|
||||
import "./run-serve.tsx";
|
||||
|
||||
if(Deno.env.get("dev"))
|
||||
{
|
||||
await import("./run-local.tsx");
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import "@able/boot-server.tsx";
|
||||
import "http://localhost:1234/boot.tsx";
|
||||
import React from "react";
|
||||
|
||||
const CTXString = React.createContext("lol");
|
||||
@ -38,7 +38,7 @@ export default ()=>
|
||||
return <CTXString.Provider value="intradestink">
|
||||
<div class="my-4 font-sans">
|
||||
<h1 class="font-black text-xl text-red-500">Title????</h1>
|
||||
<h2>subtitle!</h2>
|
||||
<h2 class="p-4">subtitle!!!!</h2>
|
||||
<p>
|
||||
<button onClick={e=>Dispatch(1)}>{Store.name}|{Store.age}?</button>
|
||||
</p>
|
||||
|
@ -3,11 +3,11 @@
|
||||
"imports":
|
||||
{
|
||||
"react":"https://esm.sh/preact@10.15.1/compat",
|
||||
"@able/":"http://localhost:4507/"
|
||||
"@able/":"http://localhost:8000/"
|
||||
},
|
||||
"tasks":
|
||||
{
|
||||
"local": "deno run -A --no-lock --reload=http://localhost:4507 app.tsx --dev",
|
||||
"serve": "deno run -A --no-lock --reload=http://localhost:4507 app.tsx"
|
||||
"local": "deno run -A --no-lock --reload app.tsx --dev",
|
||||
"serve": "deno run -A --no-lock --reload app.tsx"
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ Socket.addEventListener('message', async(event:{data:string})=>
|
||||
{
|
||||
// When a file changes, dynamically re-import it to get the updated members
|
||||
// send the updated members to any listeners for that file
|
||||
const reImport = await import(event.data+"?reload="+Math.random());
|
||||
const reImport = await import(document.location.origin+event.data+"?reload="+Math.random());
|
||||
FileListeners.get(event.data)?.forEach(reExport=>reExport(reImport));
|
||||
HMR.update();
|
||||
});
|
||||
|
@ -21,7 +21,7 @@ Configure({
|
||||
Remap: (inImports, inConfig)=>
|
||||
{
|
||||
inImports["react-original"] = inImports["react"];
|
||||
inImports["react"] = `${inConfig.Spoof}/hmr-react.tsx`;
|
||||
inImports["react"] = import.meta.resolve(`./hmr-react.tsx`);
|
||||
return inImports;
|
||||
},
|
||||
async Serve(inReq, inURL, inExt, inMap, inConfig)
|
||||
@ -33,7 +33,7 @@ Configure({
|
||||
for( const key in imp ) { members.push(key); }
|
||||
|
||||
const code =`
|
||||
import {FileListen} from "${inConfig.Spoof}/hmr-listen.tsx";
|
||||
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)=>
|
||||
|
@ -1,7 +1,25 @@
|
||||
import * as MIME from "https://deno.land/std@0.180.0/media_types/mod.ts";
|
||||
import * as HTTP from "https://deno.land/std@0.177.0/http/server.ts";
|
||||
import * as SWCW from "https://esm.sh/@swc/wasm-web@1.3.62";
|
||||
|
||||
|
||||
Deno.args.forEach(arg=>
|
||||
{
|
||||
if(arg.startsWith("--"))
|
||||
{
|
||||
const kvp = arg.substring(2).split("=");
|
||||
Deno.env.set(kvp[0], kvp[1] || "true");
|
||||
}
|
||||
});
|
||||
|
||||
const urls = {
|
||||
Cwd: new URL(`file://${Deno.cwd().replaceAll("\\", "/")}`).toString(),
|
||||
App: Deno.mainModule,
|
||||
Mod: import.meta.url,
|
||||
Look: import.meta.resolve("./boot.tsx")
|
||||
};
|
||||
|
||||
console.log(JSON.stringify(urls, null, " "));
|
||||
|
||||
type DenoConfig = {imports:Record<string, string>};
|
||||
const ImportMap:DenoConfig = {imports:{}};
|
||||
let ImportMapOriginal = {};
|
||||
@ -59,17 +77,7 @@ let Configuration:Configuration =
|
||||
Allow: "*",
|
||||
Reset: "/clear-cache",
|
||||
Spoof: "/@able",
|
||||
async Serve(inReq, inURL, inExt, inMap, inConfig)
|
||||
{
|
||||
if( inReq.headers.get("user-agent")?.startsWith("Deno") || inURL.searchParams.get("deno") )
|
||||
{
|
||||
if(inExt && Extension(inExt))
|
||||
{
|
||||
const text = await Transpile.Patch(inConfig.Proxy + inURL.pathname, "deno-"+inURL.pathname, inMap);
|
||||
return new Response(text, {headers:{"content-type":"application/javascript"}} );
|
||||
}
|
||||
}
|
||||
},
|
||||
async Serve(inReq, inURL, inExt, inMap, inConfig){},
|
||||
Remap: (inImports, inConfig)=>
|
||||
{
|
||||
const reactURL = inImports["react"];
|
||||
@ -95,17 +103,14 @@ let Configuration:Configuration =
|
||||
<div id="app"></div>
|
||||
<script type="importmap">${JSON.stringify(inMap)}</script>
|
||||
<script type="module">
|
||||
import Mount from "${inConfig.Spoof}/boot-browser.tsx";
|
||||
Mount("#app", "${parts[1]??"/app.tsx"}");
|
||||
import Mount from "${import.meta.resolve("./boot.tsx")}";
|
||||
Mount("#app", document.location.origin+"${parts[1]??"/app.tsx"}");
|
||||
</script>
|
||||
</body>
|
||||
</html>`, {status:200, headers:{"content-type":"text/html"}});
|
||||
},
|
||||
SWCOp:
|
||||
{
|
||||
env:{
|
||||
dynamicImport:false
|
||||
},
|
||||
sourceMaps: false,
|
||||
minify: true,
|
||||
jsc:
|
||||
@ -149,15 +154,23 @@ export const Transpile =
|
||||
*/
|
||||
async Patch(inPath:string, inKey:string, inMap?:DenoConfig)
|
||||
{
|
||||
const file = await fetch(inPath);
|
||||
const text = await file.text();
|
||||
|
||||
const check = this.Cache.get(inKey);
|
||||
if(check)
|
||||
{
|
||||
return check;
|
||||
}
|
||||
|
||||
let file, text;
|
||||
try
|
||||
{
|
||||
file = await fetch(inPath);
|
||||
text = await file.text();
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const remap = inMap ? (inPath:string)=>
|
||||
{
|
||||
const match = inMap.imports[inPath];
|
||||
@ -240,6 +253,19 @@ export const Transpile =
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const ExtensionPrefix =(string:string, suffix:string)=>
|
||||
{
|
||||
const lastDotIndex = string.lastIndexOf(".");
|
||||
if (lastDotIndex === -1) {
|
||||
return string;
|
||||
}
|
||||
|
||||
const prefix = string.substring(0, lastDotIndex);
|
||||
const suffixString = string.substring(lastDotIndex + 1);
|
||||
return prefix + "." + suffix + "." + suffixString;
|
||||
};
|
||||
|
||||
export const Extension =(inPath:string)=>
|
||||
{
|
||||
const posSlash = inPath.lastIndexOf("/");
|
||||
@ -255,7 +281,7 @@ export const Configure =(config:ConfigurationArgs)=>
|
||||
|
||||
await ImportMapReload();
|
||||
await SWCW.default();
|
||||
HTTP.serve(async(req: Request)=>
|
||||
const server = Deno.serve({port:parseInt(Deno.env.get("port")||"8000")}, async(req: Request)=>
|
||||
{
|
||||
const url:URL = new URL(req.url);
|
||||
const ext = Extension(url.pathname);
|
||||
@ -279,19 +305,30 @@ HTTP.serve(async(req: Request)=>
|
||||
{
|
||||
let code;
|
||||
let path;
|
||||
if(url.pathname.startsWith(Configuration.Spoof+"/"))
|
||||
let file;
|
||||
if( req.headers.get("user-agent")?.startsWith("Deno") || url.searchParams.has("deno") )
|
||||
{
|
||||
const clipRoot = import.meta.url.substring(0, import.meta.url.lastIndexOf("/"));
|
||||
const clipPath = url.pathname.substring(url.pathname.indexOf("/", 1));
|
||||
if(clipPath.startsWith("/boot-"))
|
||||
try
|
||||
{
|
||||
path = clipRoot+"/boot-browser.tsx";
|
||||
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
|
||||
{
|
||||
path = clipRoot + clipPath;
|
||||
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();
|
||||
}
|
||||
code = await Transpile.Fetch(path, url.pathname, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user