Hi,
My website is alexandruraduca.wixsite.com/popacademy
I’ve created a backend function to query collections by name and no matter what code I write I always get a 404.
Any idea what could be wrong?
Here is my code:
// sample queries:
// https://alexandruraduca.wixsite.com/popacademy/_functions/api/Cursuri
// https://alexandruraduca.wixsite.com/popacademy/_functions/api/Echipa
// https://alexandruraduca.wixsite.com/popacademy/_functions/api/Colectie
import { ok, notFound, serverError } from ‘wix-http-functions’;
import wixData from ‘wix-data’;
export function get_api(request) {
let response = {
“headers”: {
“Content-Type”: “application/json”
}
};
console.log("request received: ",request);
let collection = request.path[0]
// let query = request;
// query a collection to find matching items
return wixData.query(collection)
.find()
.then((results) => {
// matching items were found
if (results.items.length > 0) {
response.body = results.items;
return ok(response);
}
// no matching items found
response.body = {
“error”: “no items found”,
// “query”: query
};
return notFound(response);
})
// something went wrong
. catch ((error) => {
response.body = {
“error”: error,
// “query”: query
};
return serverError(response);
});
}
I even tried with this dummy code and I still get a 404
import {ok, notFound, serverError} from ‘wix-http-functions’;
export function get_testApi(request) {
let response = {
“headers”: {
“Content-Type”: “application/json”
}
};
response.body = {‘items’: [1,2,3]};
return ok(response);
}