I am new to all of this, so all of your help is appreciated. I started with the sample router.js code.
Task #1… I want to use data received from my external API call. When it is done outside of routers.js (in the Site code), it works like a charm. But when it is in routers.js, I can’t even get any of the console log to output anything…
Here is the start of my code…
import {
ok, notFound, WixRouterSitemapEntry
}
from "wix-router";
import {fetch} from 'wix-fetch';
export function agent_Router(request) {
let myID = "testuser";
let url = '/api/getUserProfile/' + myID;
fetch(url, {
method: 'get'
})
.then((httpResponse) => {
if (httpResponse.ok) {
console.log("here 1");
return httpResponse.json();
} else {
console.log("here 2");
return Promise.reject("Fetch did not succeed");
}
})
.then((json) => {
console.log("here 3");
console.log(JSON.stringify(json));
})
.catch(err => {
console.log("here 4");
console.log(err);
});
.
.
.
There are no errors in the developer console.
Once I get this working, I need to replace this sample block with the results from my API call.
const peopleData will need be be changed to the result of my API call. First things first.
That will be another thread I’m sure…
Thx