@@ -21,6 +21,7 @@ import {
2121} from "../services/ioSendService" ;
2222import MessagesService from "../services/messagesService" ;
2323import { bodyToString } from "../utils" ;
24+ import { generateLollipopLambdaGetPath } from "../../pn/routers/lollipopLambda" ;
2425
2526export const ioSendRouter = Router ( ) ;
2627
@@ -163,21 +164,68 @@ addHandler(
163164 ( ) => Math . random ( ) * 500
164165) ;
165166
167+ addHandler (
168+ ioSendRouter ,
169+ "get" ,
170+ "/api/com/v1/send/lollipop-check/test" ,
171+ lollipopMiddleware ( async ( req , res ) => {
172+ const sendLollipopLambdaGetUrl = `${ serverUrl } ${ generateLollipopLambdaGetPath ( ) } ` ;
173+ commonHandleIsTestQueryParam ( req ) ;
174+ const sendLollipopLambdaGetFetch = ( ) =>
175+ fetch ( sendLollipopLambdaGetUrl , {
176+ method : "get" ,
177+ headers : generateRequestHeaders ( req . headers , "application/json" , true )
178+ } ) ;
179+ await fetchSENDDataAndForwardResponse (
180+ sendLollipopLambdaGetFetch ,
181+ "lollipop-test" ,
182+ res
183+ ) ;
184+ } ) ,
185+ ( ) => Math . random ( ) * 500
186+ ) ;
187+
188+ addHandler (
189+ ioSendRouter ,
190+ "post" ,
191+ "/api/com/v1/send/lollipop-check/test" ,
192+ lollipopMiddleware ( async ( req , res ) => {
193+ const sendLollipopLambdaPostUrl = `${ serverUrl } ${ generateLollipopLambdaGetPath ( ) } ` ;
194+ const sendLollipopLambdaPostBodyEither = bodyToString ( req . body ) ;
195+ if ( handleLeftEitherIfNeeded ( sendLollipopLambdaPostBodyEither , res ) ) {
196+ return ;
197+ }
198+ commonHandleIsTestQueryParam ( req ) ;
199+ const sendLambdaLollipopPostFetch = ( ) =>
200+ fetch ( sendLollipopLambdaPostUrl , {
201+ method : "post" ,
202+ headers : generateRequestHeaders ( req . headers , "application/json" , true ) ,
203+ body : sendLollipopLambdaPostBodyEither . right
204+ } ) ;
205+ await fetchSENDDataAndForwardResponse (
206+ sendLambdaLollipopPostFetch ,
207+ "lollipop-test" ,
208+ res
209+ ) ;
210+ } ) ,
211+ ( ) => Math . random ( ) * 500
212+ ) ;
213+
166214const fetchSENDDataAndForwardResponse = async (
167215 fetchFunction : ( ) => Promise < globalThis . Response > ,
168216 endpointName : string ,
169217 res : Response
170218) => {
171219 try {
172- const sendQResponse = await fetchFunction ( ) ;
220+ const sendResponse = await fetchFunction ( ) ;
173221
174- const contentType = sendQResponse . headers . get ( "content-type" ) ;
175- const responseBodyBuffer = await sendQResponse . arrayBuffer ( ) ;
222+ const contentType = sendResponse . headers . get ( "content-type" ) ;
223+ const responseBodyBuffer = await sendResponse . arrayBuffer ( ) ;
176224 const body = Buffer . from ( responseBodyBuffer ) ;
177225 if ( contentType ) {
178226 res . setHeader ( "Content-Type" , contentType ) ;
179227 }
180- res . status ( sendQResponse . status ) . send ( body ) ;
228+ res . status ( sendResponse . status ) . send ( body ) ;
181229 } catch ( e ) {
182230 const errorMessage = unknownToString ( e ) ;
183231 res
0 commit comments