starting to remove spoof path
This commit is contained in:
parent
e5176e0eee
commit
66b148d7f5
@ -4,6 +4,7 @@ import * as SWCW from "https://esm.sh/@swc/wasm-web@1.3.62";
|
||||
|
||||
type DenoConfig = {imports:Record<string, string>};
|
||||
const ImportMap:DenoConfig = {imports:{}};
|
||||
let ImportMapOriginal = {};
|
||||
const ImportMapReload =async()=>
|
||||
{
|
||||
let json:DenoConfig;
|
||||
@ -14,6 +15,7 @@ const ImportMapReload =async()=>
|
||||
json = await resp.json();
|
||||
if(!json?.imports)
|
||||
{ throw new Error("imports not specified in deno.json") }
|
||||
ImportMapOriginal = json;
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
@ -29,12 +31,14 @@ const ImportMapReload =async()=>
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
const mapKey = (Configuration.Spoof.startsWith("/") ? Configuration.Spoof.substring(1) : Configuration.Spoof)+"/";
|
||||
if(!json.imports[mapKey])
|
||||
{
|
||||
console.log(`"${mapKey}" specifier not defined in import map`);
|
||||
}
|
||||
json.imports[mapKey] = Configuration.Spoof+"/";
|
||||
*/
|
||||
|
||||
if(!json.imports["react"])
|
||||
{
|
||||
@ -59,9 +63,11 @@ let Configuration:Configuration =
|
||||
{
|
||||
if( inReq.headers.get("user-agent")?.startsWith("Deno") || inURL.searchParams.get("deno") )
|
||||
{
|
||||
const file = await fetch(inConfig.Proxy + inURL.pathname);
|
||||
const text = await file.text();
|
||||
return new Response(Transpile.Patch(text, "deno-"+inURL.pathname, inMap), {headers:{"content-type":"application/javascript"}} );
|
||||
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"}} );
|
||||
}
|
||||
}
|
||||
},
|
||||
Remap: (inImports, inConfig)=>
|
||||
@ -141,17 +147,16 @@ export const Transpile =
|
||||
/**
|
||||
* Converts dynamic module imports in to static, also can resolve paths with an import map
|
||||
*/
|
||||
Patch(inText:string, inKey:string|false = false, inMap?:DenoConfig)
|
||||
async Patch(inPath:string, inKey:string, inMap?:DenoConfig)
|
||||
{
|
||||
const file = await fetch(inPath);
|
||||
const text = await file.text();
|
||||
|
||||
if(inKey)
|
||||
{
|
||||
const check = this.Cache.get(inKey);
|
||||
if(check)
|
||||
{
|
||||
return check;
|
||||
}
|
||||
}
|
||||
|
||||
const remap = inMap ? (inPath:string)=>
|
||||
{
|
||||
@ -181,11 +186,11 @@ export const Transpile =
|
||||
}
|
||||
: (inPath:string)=>inPath;
|
||||
let match, regex;
|
||||
let convertedBody = inText;
|
||||
let convertedBody = text;
|
||||
|
||||
// remap static imports
|
||||
regex = /from\s+(['"`])(.*?)\1/g;
|
||||
while ((match = regex.exec(inText)))
|
||||
while ((match = regex.exec(text)))
|
||||
{
|
||||
const importStatement = match[0];
|
||||
const importPath = match[2];
|
||||
@ -195,7 +200,7 @@ export const Transpile =
|
||||
// convert dynamic imports into static (to work around deno deploy)
|
||||
const staticImports = [];
|
||||
regex = /(?<![\w.])import\(([^)]+)(?!import\b)\)/g;
|
||||
while ((match = regex.exec(inText)))
|
||||
while ((match = regex.exec(text)))
|
||||
{
|
||||
const importStatement = match[0];
|
||||
const importPath = remap(match[1].substring(1, match[1].length-1));
|
||||
@ -209,7 +214,7 @@ export const Transpile =
|
||||
inKey && this.Cache.set(inKey, convertedBody);
|
||||
return convertedBody;
|
||||
},
|
||||
Fetch: async function(inPath:string, inKey:string, inCheckCache=true)
|
||||
async Fetch(inPath:string, inKey:string, inCheckCache=true)
|
||||
{
|
||||
const check = this.Cache.get(inPath);
|
||||
if(check && inCheckCache)
|
||||
|
56
things.md
Normal file
56
things.md
Normal file
@ -0,0 +1,56 @@
|
||||
# Outpost
|
||||
|
||||
## Deno Deploy
|
||||
```
|
||||
accept: */*
|
||||
accept-encoding: gzip, br
|
||||
accept-language: *
|
||||
cdn-loop: deno;s=deno;d=ah40t9m8n54g
|
||||
host: bad-goat-66.deno.dev
|
||||
user-agent: Deno/1.34.1
|
||||
```
|
||||
|
||||
## Deno
|
||||
```
|
||||
accept: */*
|
||||
accept-encoding: gzip, br
|
||||
accept-language: *
|
||||
host: bad-goat-66.deno.dev
|
||||
user-agent: Deno/1.34.3
|
||||
```
|
||||
|
||||
## Edge
|
||||
```
|
||||
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
|
||||
accept-encoding: gzip, deflate, br
|
||||
accept-language: en-US,en;q=0.9
|
||||
host: bad-goat-66.deno.dev
|
||||
referer: https://dash.deno.com/
|
||||
sec-ch-ua: "Microsoft Edge";v="117", "Not;A=Brand";v="8", "Chromium";v="117"
|
||||
sec-ch-ua-mobile: ?0
|
||||
sec-ch-ua-platform: "Windows"
|
||||
sec-fetch-dest: iframe
|
||||
sec-fetch-mode: navigate
|
||||
sec-fetch-site: cross-site
|
||||
upgrade-insecure-requests: 1
|
||||
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.0.0
|
||||
```
|
||||
|
||||
## Firefox
|
||||
```
|
||||
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
|
||||
accept-encoding: gzip, deflate, br
|
||||
accept-language: en-US,en;q=0.5
|
||||
host: bad-goat-66.deno.dev
|
||||
sec-fetch-dest: document
|
||||
sec-fetch-mode: navigate
|
||||
sec-fetch-site: cross-site
|
||||
te: trailers
|
||||
upgrade-insecure-requests: 1
|
||||
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0
|
||||
```
|
||||
|
||||
When a requet comes in:
|
||||
- if its for a transpile-able document:
|
||||
- if its a request from deno:
|
||||
-
|
Loading…
Reference in New Issue
Block a user