11"use strict" ;
2- var __importDefault = ( this && this . __importDefault ) || function ( mod ) {
3- return ( mod && mod . __esModule ) ? mod : { "default" : mod } ;
4- } ;
52Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
63const proxy_1 = require ( "../../../../lib/proxy" ) ;
74const requestly_core_1 = require ( "@requestly/requestly-core" ) ;
85const proxy_ctx_helper_1 = require ( "../../helpers/proxy_ctx_helper" ) ;
96const utils_1 = require ( "../utils" ) ;
10- const fs_1 = __importDefault ( require ( "fs" ) ) ;
117const http_helpers_1 = require ( "../../helpers/http_helpers" ) ;
128const utils_2 = require ( "../../../../utils" ) ;
139const constants_1 = require ( "../../constants" ) ;
@@ -17,16 +13,32 @@ const process_modify_response_action = async (action, ctx) => {
1713 return ( 0 , utils_1 . build_action_processor_response ) ( action , false ) ;
1814 }
1915 if ( ctx . currentHandler === proxy_1 . PROXY_HANDLER_TYPE . ON_REQUEST ) {
20- if ( action . responseType === requestly_core_1 . CONSTANTS . RESPONSE_BODY_TYPES . STATIC
21- && action . serveWithoutRequest ) {
16+ if ( action . serveWithoutRequest ) {
2217 let contentType , finalBody ;
18+ if ( action . responseType === requestly_core_1 . CONSTANTS . RESPONSE_BODY_TYPES . LOCAL_FILE ) {
19+ try {
20+ finalBody = ( 0 , utils_1 . get_file_contents ) ( action . response ) ;
21+ }
22+ catch ( err ) {
23+ console . log ( "Error reading file" , err ) ;
24+ return ( 0 , utils_1 . build_action_processor_response ) ( action , false ) ;
25+ }
26+ }
27+ else if ( action . responseType === requestly_core_1 . CONSTANTS . RESPONSE_BODY_TYPES . STATIC ) {
28+ finalBody = action . response ;
29+ }
30+ else {
31+ return ( 0 , utils_1 . build_action_processor_response ) ( action , false ) ;
32+ }
2333 try {
24- finalBody = JSON . parse ( action . response ) ;
34+ const parsedResponse = JSON . parse ( finalBody ) ;
35+ if ( action . responseType === requestly_core_1 . CONSTANTS . RESPONSE_BODY_TYPES . STATIC ) {
36+ finalBody = parsedResponse ;
37+ }
2538 contentType = "application/json" ;
2639 }
2740 catch ( _a ) {
2841 contentType = "text/plain" ;
29- finalBody = action . response ;
3042 }
3143 const status = action . statusCode || 200 ;
3244 const finalHeaders = { "Content-Type" : contentType } ;
@@ -70,7 +82,7 @@ const modify_response = (ctx, new_resp, status_code) => {
7082const modify_response_using_local = ( action , ctx ) => {
7183 let data ;
7284 try {
73- data = fs_1 . default . readFileSync ( action . response , "utf-8" ) ;
85+ data = ( 0 , utils_1 . get_file_contents ) ( action . response ) ;
7486 modify_response ( ctx , data , action . statusCode ) ;
7587 }
7688 catch ( err ) {
0 commit comments