Skip to content

Instantly share code, notes, and snippets.

@tsh-code
Created May 6, 2024 09:44
Show Gist options
  • Save tsh-code/3b64b1ebb5ac66f56bab360b71f285e0 to your computer and use it in GitHub Desktop.
Save tsh-code/3b64b1ebb5ac66f56bab360b71f285e0 to your computer and use it in GitHub Desktop.
Preloaded translation lambdas API stack
import { Api, Function, StackContext, use } from "sst/constructs";
import { Translations } from "./Translations";
export function API({ stack }: StackContext) {
const { translationFn, translationFns } = use(Translations);
const staticTranslationLambdas: Record<string, { function: Function }> = Object.fromEntries(
translationFns.map(({ key, fn }) => [`POST /api/translate/${key}`, { function: fn }])
);
const api = new Api(stack, "translation-api", {
routes: {
"POST /api/translate/{languageCode}": {
function: translationFn,
},
...staticTranslationLambdas,
},
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment