From f92b8852b366facde70d4cf20f87a262cbaa58c8 Mon Sep 17 00:00:00 2001 From: Amit Moryossef Date: Sun, 15 Sep 2024 21:25:59 +0200 Subject: [PATCH] feat(gateway): add spoken to signed video --- functions/src/gateway/controller.ts | 17 ++++++----------- functions/src/gateway/spoken-to-signed.ts | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 functions/src/gateway/spoken-to-signed.ts diff --git a/functions/src/gateway/controller.ts b/functions/src/gateway/controller.ts index ac079c47..ae3ff0ab 100644 --- a/functions/src/gateway/controller.ts +++ b/functions/src/gateway/controller.ts @@ -7,14 +7,12 @@ import {onRequest} from 'firebase-functions/v2/https'; import {unkeyAuth} from './middleware'; import {HttpsOptions} from 'firebase-functions/lib/v2/providers/https'; import {getAppCheck} from 'firebase-admin/app-check'; -import {createProxyMiddleware} from 'http-proxy-middleware'; -import {paths} from './utils'; import {avatars} from './avatars'; import {me} from './me'; +import {spokenToSigned} from './spoken-to-signed'; // The public APP ID of the sign-mt web app const APP_ID = '1:665830225099:web:18e0669d5847a4b047974e'; -const FUNCTIONS_URL = 'https://us-central1-sign-mt.cloudfunctions.net'; // Create and cache an App Check token for the sign-mt web app let appCheckAPIKey = Promise.resolve({token: '', expires: 0}); @@ -39,6 +37,10 @@ export async function getAppCheckKey(req: Request, res: Response, next: NextFunc } res.locals.appCheckToken = token; + res.locals.headers = { + 'X-Firebase-AppCheck': token, + 'X-AppCheck-Token': token, + }; return next(); } @@ -50,14 +52,7 @@ app.use(unkeyAuth); app.use(getAppCheckKey); app.options('*', (req, res) => res.status(200).end()); -app.use( - paths('spoken-text-to-signed-pose'), - createProxyMiddleware({ - target: `${FUNCTIONS_URL}/spoken_text_to_signed_pose`, - changeOrigin: true, - }) -); - +spokenToSigned(app); me(app); avatars(app); diff --git a/functions/src/gateway/spoken-to-signed.ts b/functions/src/gateway/spoken-to-signed.ts new file mode 100644 index 00000000..0a8d8e50 --- /dev/null +++ b/functions/src/gateway/spoken-to-signed.ts @@ -0,0 +1,21 @@ +import {Application} from 'express'; +import {paths} from './utils'; +import {createProxyMiddleware} from 'http-proxy-middleware'; + +export function spokenToSigned(app: Application) { + app.use( + paths('spoken-text-to-signed-pose'), + createProxyMiddleware({ + target: 'https://us-central1-sign-mt.cloudfunctions.net/spoken_text_to_signed_pose', + changeOrigin: true, + }) + ); + + app.use( + paths('spoken-text-to-signed-video'), + createProxyMiddleware({ + target: 'https://us-central1-sign-mt.cloudfunctions.net/spoken_text_to_signed_video', + changeOrigin: true, + }) + ); +}