Compare commits
No commits in common. "auto-api" and "master" have entirely different histories.
@ -1,37 +0,0 @@
|
|||||||
import * as Endpoints from ">able/api.tsx";
|
|
||||||
|
|
||||||
type EndpointOptions = Record<string, string|number|boolean>;
|
|
||||||
type EndpointHandler = (options:EndpointOptions)=>unknown;
|
|
||||||
|
|
||||||
export function Call(functionName:string, options:EndpointOptions)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// @ts-ignore we're catchig this anyway
|
|
||||||
const results = Endpoints[functionName](options);
|
|
||||||
return new Response(JSON.stringify(results));
|
|
||||||
}
|
|
||||||
catch(e)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function proxy(functionName:string)
|
|
||||||
{
|
|
||||||
return async( ...args:string[])=>
|
|
||||||
{
|
|
||||||
const resp = await fetch(`/api/${functionName}/${args.join("/")}`);
|
|
||||||
const json = await resp.json();
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const parts:string[] = [];
|
|
||||||
for(const member in Endpoints)
|
|
||||||
{
|
|
||||||
member != "default" && parts.push(`export const ${member} = ${proxy.name}("${member}")`);
|
|
||||||
}
|
|
||||||
export const Spoof = `${proxy.toString()}
|
|
||||||
${parts.join("\n")};
|
|
||||||
`;
|
|
5
api.tsx
5
api.tsx
@ -2,8 +2,3 @@ export default (req:Request):Response|false=>
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const test =()=>
|
|
||||||
{
|
|
||||||
return {test:true};
|
|
||||||
}
|
|
4
app.tsx
4
app.tsx
@ -1,8 +1,6 @@
|
|||||||
import {test} from ">able/api.tsx";
|
|
||||||
|
|
||||||
import * as ISO from ">able/iso-elements.tsx";
|
import * as ISO from ">able/iso-elements.tsx";
|
||||||
|
|
||||||
console.log(test());
|
console.log(ISO)
|
||||||
|
|
||||||
export default ()=><div>
|
export default ()=><div>
|
||||||
<h1 class="p-4 bg-red-500 text-white">App</h1>
|
<h1 class="p-4 bg-red-500 text-white">App</h1>
|
||||||
|
@ -2,7 +2,6 @@ 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 * as SWCW from "https://esm.sh/@swc/wasm-web@1.3.62";
|
||||||
import { HuntConfig, Root } from "./checker.tsx";
|
import { HuntConfig, Root } from "./checker.tsx";
|
||||||
import CustomServe from ">able/api.tsx";
|
import CustomServe from ">able/api.tsx";
|
||||||
import { Call, Spoof } from "./api-extract.tsx";
|
|
||||||
|
|
||||||
type DenoConfig = {imports:Record<string, string>};
|
type DenoConfig = {imports:Record<string, string>};
|
||||||
const ImportMap:DenoConfig = {imports:{}};
|
const ImportMap:DenoConfig = {imports:{}};
|
||||||
@ -27,6 +26,7 @@ const ImportMapReload =async()=>
|
|||||||
imports[key] = "/"+key;
|
imports[key] = "/"+key;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ImportMap.imports = Configuration.Remap(imports, Configuration);
|
ImportMap.imports = Configuration.Remap(imports, Configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,9 +179,6 @@ export default async()=>
|
|||||||
{
|
{
|
||||||
/** pathname with no leading slash */
|
/** pathname with no leading slash */
|
||||||
const clippedPath = decodeURI(url.pathname.substring(1));
|
const clippedPath = decodeURI(url.pathname.substring(1));
|
||||||
if(clippedPath == ">able/api.tsx"){
|
|
||||||
return new Response(Spoof, {headers:{"content-type":"application/javascript"}});
|
|
||||||
}
|
|
||||||
proxy = import.meta.resolve(clippedPath);
|
proxy = import.meta.resolve(clippedPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,21 +188,6 @@ export default async()=>
|
|||||||
{
|
{
|
||||||
return custom;
|
return custom;
|
||||||
}
|
}
|
||||||
|
|
||||||
// auto-api
|
|
||||||
if(url.pathname.startsWith("/api/"))
|
|
||||||
{
|
|
||||||
const functionName = url.pathname.split("/")[2];
|
|
||||||
const options:Record<string, string|number|boolean> = {};
|
|
||||||
url.searchParams.forEach((value, key)=>{options[key] = value});
|
|
||||||
const response = Call(functionName, options);
|
|
||||||
if(response)
|
|
||||||
{
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// full api
|
|
||||||
const api = await Configuration.Serve(req, url, ext, ImportMap, Configuration);
|
const api = await Configuration.Serve(req, url, ext, ImportMap, Configuration);
|
||||||
if(api)
|
if(api)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user