CORS Policy

Change the below origin strings to your own origin.

This should resolve your CORS issue.

import { ok , badRequest , response } from ‘wix-http-functions’ ;

function validate ( origin ) {
if ( origin == “http://localhost:4200” || origin == “http://localhost:4201” ) {
return true ;
} else {
return false ;
}
}

export function options_yourFunctionName ( request ) {
console . log ( request );

let  headers  = { 
    "Access-Control-Allow-Methods" :  "POST, GET, OPTIONS" , 
    "Access-Control-Max-Age" :  "86400" 
} 

if  ( validate ( request . headers . origin )) { 
    headers [ "Access-Control-Allow-Origin" ] =  request . headers . origin ; 
} 

return  response ({  "status" :  204 ,  "headers" :  headers  }); 

}

export function post_yourFunctionName ( request ) {
console . log ( “post_duxLogin” );
const _response = {
“headers” : {
“Content-Type” : “application/json” ,
}
};

if  ( validate ( request . headers . origin )) { 
    _response . headers [ "Access-Control-Allow-Origin" ] = 
        request . headers . origin ; 
    _response . headers [ "Access-Control-Allow-Headers" ] =  "Content-Type" ; 
} 

// Perform other things here.... 

}