-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
28 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
export const prerender = false; | ||
import type { DocRequest } from "@customTypes/types"; | ||
import type { APIRoute } from "astro"; | ||
import type {DocRequest} from "@customTypes/types"; | ||
import type {APIRoute} from "astro"; | ||
|
||
export const POST: APIRoute = async ({ request }) => { | ||
const baseUrl = "https://doc-api.bibleineverylanguage.org"; | ||
const body = (await request.json()) as DocRequest; | ||
const docUrl = body.generate_docx | ||
? `${baseUrl}/documents_docx` | ||
: `${baseUrl}/documents`; | ||
try { | ||
const res = await fetch(docUrl, { | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify(body), | ||
}); | ||
if (!res.ok) { | ||
throw new Error(res.statusText); | ||
} | ||
const taskJson = await res.json(); | ||
const { task_id } = taskJson; | ||
return new Response(task_id as string, { | ||
status: 200, | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
return new Response(null, { | ||
status: 400, | ||
}); | ||
} | ||
export const POST: APIRoute = async ({request, locals}) => { | ||
const {DOC_BASE_URL: baseUrl} = locals.runtime.env; | ||
const body = (await request.json()) as DocRequest; | ||
const docUrl = body.generate_docx | ||
? `${baseUrl}/documents_docx` | ||
: `${baseUrl}/documents`; | ||
try { | ||
const res = await fetch(docUrl, { | ||
method: "POST", | ||
headers: {"Content-Type": "application/json"}, | ||
body: JSON.stringify(body), | ||
}); | ||
if (!res.ok) { | ||
throw new Error(res.statusText); | ||
} | ||
const taskJson = await res.json(); | ||
const {task_id} = taskJson; | ||
return new Response(task_id as string, { | ||
status: 200, | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
return new Response(null, { | ||
status: 400, | ||
}); | ||
} | ||
}; |