remove flash server

This commit is contained in:
Seth Trowbridge 2023-04-30 16:45:35 -04:00
parent 3feb8d3b6b
commit ca892eed6a

View File

@ -2,13 +2,21 @@ import * as ESBuild from 'https://deno.land/x/esbuild@v0.17.4/mod.js';
import * as MIME from "https://deno.land/std@0.180.0/media_types/mod.ts"; import * as MIME from "https://deno.land/std@0.180.0/media_types/mod.ts";
import { debounce } from "https://deno.land/std@0.151.0/async/debounce.ts"; import { debounce } from "https://deno.land/std@0.151.0/async/debounce.ts";
import { parse as JSONC} from "https://deno.land/std@0.185.0/jsonc/mod.ts"; import { parse as JSONC} from "https://deno.land/std@0.185.0/jsonc/mod.ts";
import { toFileUrl } from "https://deno.land/std@0.185.0/path/mod.ts"; import * as HTTP from "https://deno.land/std@0.185.0/http/server.ts"
import SSR from "https://esm.sh/v113/preact-render-to-string@6.0.2"; import SSR from "https://esm.sh/v113/preact-render-to-string@6.0.2";
import Prepass from "https://esm.sh/preact-ssr-prepass@1.2.0"; import Prepass from "https://esm.sh/preact-ssr-prepass@1.2.0";
import * as Twind from "https://esm.sh/@twind/core@1.1.3"; import * as Twind from "https://esm.sh/@twind/core@1.1.3";
import React from "react"; import React from "react";
import * as Iso from "@eno/iso"; import * as Iso from "@eno/iso";
/**
* things you cant do on deno deploy:
* imports inside deno.json
* dynamic imports
* Deno.mainModule
* Deno.serve
*/
/** /**
* Setup a transpiler. * Setup a transpiler.
* @param inDevMode When true, starts a file-watcher * @param inDevMode When true, starts a file-watcher
@ -65,7 +73,7 @@ function Transpiler(inDevMode:boolean)
const Sockets:Set<WebSocket> = new Set(); const Sockets:Set<WebSocket> = new Set();
const SocketsBroadcast =(inData:string)=>{ for (const socket of Sockets){ socket.send(inData); } } const SocketsBroadcast =(inData:string)=>{ for (const socket of Sockets){ socket.send(inData); } }
const SocketsHandler = inDevMode ? (_req:Request)=> const SocketsHandler = inDevMode ? (_req:Request):false|Response=>
{ {
if(_req.headers.get("upgrade") == "websocket") if(_req.headers.get("upgrade") == "websocket")
{ {
@ -86,7 +94,7 @@ function Transpiler(inDevMode:boolean)
return false; return false;
} }
: :
()=>false; ():false=>false;
const watcher =async()=> const watcher =async()=>
{ {
@ -272,7 +280,7 @@ async function Server(App:React.FunctionComponent, TwindInst:Twind.Twind)
} }
else if(App && TwindInst) else if(App && TwindInst)
{ {
Deno.serve({ port: Deno.env.get("port")||3000 }, async(_req:Request) => HTTP.serve(async(_req:Request) =>
{ {
const url:URL = new URL(_req.url); const url:URL = new URL(_req.url);
const pathParts = url.pathname.substring(1, url.pathname.endsWith("/") ? url.pathname.length-1 : url.pathname.length).split("/"); const pathParts = url.pathname.substring(1, url.pathname.endsWith("/") ? url.pathname.length-1 : url.pathname.length).split("/");
@ -280,7 +288,7 @@ async function Server(App:React.FunctionComponent, TwindInst:Twind.Twind)
const pathExt:string|undefined = pathLast?.split(".")[1]; const pathExt:string|undefined = pathLast?.split(".")[1];
const resp = SocketsHandler(_req); const resp = SocketsHandler(_req);
if(resp){ return resp; } if(resp){ return resp;}
console.log(url.pathname); console.log(url.pathname);
@ -393,6 +401,6 @@ async function Server(App:React.FunctionComponent, TwindInst:Twind.Twind)
console.log(error); console.log(error);
return new Response(error, {status:404}); return new Response(error, {status:404});
} }
}); }, { port: parseInt(Deno.env.get("port")||"3000" )});
} }
} }