i am trying to call the backend function from the wix HTTP function module.
HTTP - function code
export function post_addToken(request) {
let headers = request.headers;
// console.log(headers);
// console.log(headers.token);
let token = headers.token;
let options = {
“headers” : {
“Content-Type” : “application/json”
}
};
if (token){
var tokenResponse = getTokenWithAPI(token).then((response) => {
tokenResponse = JSON.parse(response);
console.log( "Json Token items " + tokenResponse.items[ 0 ].clientToken);
return tokenResponse;
})
if (tokenResponse.items[ 0 ].clientToken){ // this is undefined
console.log( “Inside if” );
options.body = {
“items” : valid request
};
return ok(options);
}
} else {
options.body = {
“error” : 404 Token Not Found
};
return notFound(options);
}
}
----my wix backend code—
export async function getTokenWithAPI(token){
// console.log(“inside fetch token value”+token);
let res = await fetch( URL ) ;
// console.log("raw res "+ res);
res = await res.text();
return res;
}
i want to return HTTP ok or not found options depending upon if the value from wix backend exists or not.
can anyone help me here?
tokenResponse value is undefined, and the same value I can access inside then function.
what am i missing here?
i will be exposing the HTTP function to 3rd party vendors.