Skip to content

Commit

Permalink
make something else an env var
Browse files Browse the repository at this point in the history
  • Loading branch information
wkelly17 committed Feb 6, 2025
1 parent 4c9398c commit dbc78b5
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions src/pages/api/doc.ts
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,
});
}
};

0 comments on commit dbc78b5

Please sign in to comment.