route fixes #12
This commit is contained in:
parent
767e681640
commit
0a5d96ce7a
@ -12,7 +12,6 @@
|
|||||||
"tasks":
|
"tasks":
|
||||||
{
|
{
|
||||||
"install": "deno install -f -A --unstable --no-lock -n eno server.tsx",
|
"install": "deno install -f -A --unstable --no-lock -n eno server.tsx",
|
||||||
"run": "deno run -A --unstable --no-lock server.tsx",
|
|
||||||
"host": "deno run -A --unstable https://deno.land/std@0.181.0/http/file_server.ts",
|
"host": "deno run -A --unstable https://deno.land/std@0.181.0/http/file_server.ts",
|
||||||
"example": "cd example && pwd && deno task dev"
|
"example": "cd example && pwd && deno task dev"
|
||||||
}
|
}
|
||||||
|
27
server.tsx
27
server.tsx
@ -100,7 +100,7 @@ try
|
|||||||
if(importReact)
|
if(importReact)
|
||||||
{
|
{
|
||||||
ImportObject.imports["react-original"] = importReact;
|
ImportObject.imports["react-original"] = importReact;
|
||||||
ImportObject.imports["react"] = `./${LibPath}/react.tsx`;
|
ImportObject.imports["react"] = `/${LibPath}/react.tsx`;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -120,18 +120,23 @@ try
|
|||||||
const importIso = ImportObject.imports["@eno/iso"];
|
const importIso = ImportObject.imports["@eno/iso"];
|
||||||
if(importIso)
|
if(importIso)
|
||||||
{
|
{
|
||||||
ImportObject.imports["@eno/iso"] = `./${LibPath}/iso.tsx`;
|
ImportObject.imports["@eno/iso"] = `/${LibPath}/iso.tsx`;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Object.entries(ImportObject.imports).forEach(([key, value])=>{
|
||||||
|
if(value.startsWith("./") && ImportObject.imports)
|
||||||
|
{
|
||||||
|
ImportObject.imports[key] = value.substring(1);
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
console.log(`No "imports" found in configuration`);
|
console.log(`No "imports" found in configuration`);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(e)
|
catch(e)
|
||||||
{
|
{
|
||||||
@ -143,6 +148,11 @@ Deno.serve({ port: Deno.args[0]||3000 }, async(_req:Request) =>
|
|||||||
{
|
{
|
||||||
const url:URL = new URL(_req.url);
|
const url:URL = new URL(_req.url);
|
||||||
const fsPath = Deno.cwd()+url.pathname;
|
const fsPath = Deno.cwd()+url.pathname;
|
||||||
|
const pathParts = url.pathname.substring(1, url.pathname.endsWith("/") ? url.pathname.length-1 : url.pathname.length).split("/");
|
||||||
|
const pathLast = pathParts[pathParts.length-1];
|
||||||
|
const pathExt:string|undefined = pathLast.split(".")[1];
|
||||||
|
|
||||||
|
console.log(pathParts, pathLast, pathExt);
|
||||||
|
|
||||||
console.log(`Request for "${url.pathname}"...`);
|
console.log(`Request for "${url.pathname}"...`);
|
||||||
|
|
||||||
@ -177,10 +187,9 @@ Deno.serve({ port: Deno.args[0]||3000 }, async(_req:Request) =>
|
|||||||
let type = `text/html`;
|
let type = `text/html`;
|
||||||
let body:BodyInit = ``;
|
let body:BodyInit = ``;
|
||||||
|
|
||||||
const isLib = url.pathname.startsWith(`/${LibPath}/`)
|
const isLib = url.pathname.startsWith(`/${LibPath}/`);
|
||||||
|
|
||||||
// serve .tsx .jsx .ts .js
|
if(Transpileable(pathLast))
|
||||||
if(Transpileable(url.pathname))
|
|
||||||
{
|
{
|
||||||
type = `application/javascript`;
|
type = `application/javascript`;
|
||||||
if(isLib)
|
if(isLib)
|
||||||
@ -190,8 +199,6 @@ Deno.serve({ port: Deno.args[0]||3000 }, async(_req:Request) =>
|
|||||||
else if(!url.searchParams.get("reload"))
|
else if(!url.searchParams.get("reload"))
|
||||||
{
|
{
|
||||||
const path = `file://${Deno.cwd().replaceAll("\\", "/")+url.pathname}`;
|
const path = `file://${Deno.cwd().replaceAll("\\", "/")+url.pathname}`;
|
||||||
console.log(path);
|
|
||||||
|
|
||||||
const imp = await import(path);
|
const imp = await import(path);
|
||||||
const members = [];
|
const members = [];
|
||||||
for( const key in imp ) { members.push(key); }
|
for( const key in imp ) { members.push(key); }
|
||||||
@ -215,9 +222,9 @@ FileListen("${url.pathname}", reloadHandler);`;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// serve static media
|
// serve static media
|
||||||
else if( url.pathname.endsWith("/") === false)
|
else if( pathExt )
|
||||||
{
|
{
|
||||||
type = MIME.typeByExtension(url.pathname.substring(url.pathname.lastIndexOf("."))) || "text/html";
|
type = MIME.typeByExtension(pathExt) || "text/html";
|
||||||
if(isLib)
|
if(isLib)
|
||||||
{
|
{
|
||||||
const _fetch = await fetch(import.meta.resolve(`.${url.pathname}`));
|
const _fetch = await fetch(import.meta.resolve(`.${url.pathname}`));
|
||||||
|
Loading…
Reference in New Issue
Block a user