Any suggestions? i want to call/connect the database field value from my backend
Backend -
import { fetch } from 'wix-fetch';
import wixData from 'wix-data';
export async function getData() {
const apiKey = "xxxxxxxxxxxxxx";
let id = await wixData.get("myDatabaseName", "mydatabaseFieldKey")
.then((results) => {
let item = results.title
})
.catch((err) => {
let errorMsg = err
})
const response = await fetch("https://www.exampleapis.com/s?Settings&id=" + id + "&key=" + apiKey, {
method: 'get'
});
if (response.status >= 200 && response.status < 300) {
const res = await response.json();
return res;
}
let res = await response.json();
return res;
}
Frontend
import { getData } from 'backend/getDatach.jsw';
$w.onReady(function () {
getData()
.then((response) => {
let chName = response.items[0].title;
$w("#chaName").text = chName;
});
});
#backend code #database