PronounsPage/server/api/pronouns/[...pronoun].get.ts

23 lines
837 B
TypeScript

import { getLocale, loadConfig, loadPronouns, loadTranslator } from '~/server/data.ts';
import { getPronounExamples, makePublicPronoun } from '~/server/pronouns.ts';
import { buildPronoun } from '~/src/buildPronoun.ts';
export default defineEventHandler(async (event) => {
const locale = getLocale(event);
const [config, translator, pronouns] = await Promise.all([
loadConfig(locale),
loadTranslator(locale),
loadPronouns(locale),
]);
checkIsConfigEnabledOr404(config, 'pronouns');
const pronoun = buildPronoun(pronouns, getRouterParam(event, 'pronoun') ?? null, config, translator);
if (!pronoun) {
throw createError({
status: 404,
statusMessage: 'Not Found',
});
}
return makePublicPronoun(pronoun, await getPronounExamples(event));
});