@@ -5,8 +5,6 @@ import buildButtons from '../modules/buildButtons';
55import getTargetFrame from '../modules/getTargetFrame' ;
66
77export default async ( req , context ) => {
8- const debug = process . env . DEBUG_MODE ;
9- const host = process . env . URL ;
108 const payload = await parseRequest ( req ) ;
119 let from = 'poster' ;
1210 let buttonId = null ;
@@ -17,7 +15,33 @@ export default async (req, context) => {
1715 buttonId = payload . untrustedData ?. buttonIndex ;
1816 }
1917
20- const { frameSrc, frameName } = getTargetFrame ( from , buttonId , frames ) ;
18+ const { frameSrc, frameName, redirectUrl } = getTargetFrame ( from , buttonId , frames ) ;
19+ if ( redirectUrl ) {
20+ return await respondWithRedirect ( redirectUrl ) ;
21+ } else if ( frameSrc ) {
22+ return await respondWithFrame ( frameName , frameSrc , payload ) ;
23+ } else {
24+ console . error ( `🤷🏻` )
25+ }
26+ }
27+
28+ const respondWithRedirect = ( redirectUrl ) => {
29+ const internalRedirectUrl = new URL ( `${ process . env . URL } /redirect` )
30+ internalRedirectUrl . searchParams . set ( 'redirectUrl' , redirectUrl ) ;
31+ return new Response ( '<div>redirect</div>' ,
32+ {
33+ status : 302 ,
34+ headers : {
35+ 'Location' : internalRedirectUrl ,
36+ } ,
37+ }
38+ ) ;
39+ }
40+
41+ const respondWithFrame = async ( frameName , frameSrc , payload ) => {
42+ const debug = process . env . DEBUG_MODE ;
43+ const host = process . env . URL ;
44+
2145 const frameContent = {
2246 image : `` ,
2347 buttons : buildButtons ( frameSrc . buttons ) ,
0 commit comments