Created
May 6, 2024 09:44
-
-
Save tsh-code/3b64b1ebb5ac66f56bab360b71f285e0 to your computer and use it in GitHub Desktop.
Preloaded translation lambdas API stack
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
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