diff --git a/.well-known/openapi.yaml b/.well-known/openapi.yaml index 2f8f442..5dd5d58 100644 --- a/.well-known/openapi.yaml +++ b/.well-known/openapi.yaml @@ -1,4 +1,4 @@ -openapi: 3.0.1 +openapi: 3.1.0 info: title: TypeScript Twoslash API description: A REST API for transforming TypeScript code using twoslash. diff --git a/mod.ts b/mod.ts index 8444694..f164f8d 100644 --- a/mod.ts +++ b/mod.ts @@ -21,6 +21,26 @@ router.get("/", () => { POST: "/twoslash - Accepts a JSON & Form Data body with the following properties: code, extension, and options." }) }); + +router.get("/twoslash", async ({ request }) => { + const url = new URL(request.url); + const decodedQuery: TwoslashRequestOptions = JSON.parse(url.searchParams.get("options")!) + const { code, extension, ...opts } = decodedQuery; + + try { + const twoslash = await twoslasher(code, extension, opts); + console.log("twoslash ", twoslash); + return Response.json(twoslash); + } catch (e) { + return new Response(e.toString(), { + status: 400, + headers: new Headers([ + ['Content-Type', "text/plain"] + ]), + }); + } +}); + router.post("/twoslash", async ({ request }) => { const headers = request.headers; const contentType = headers.get("content-type");