Do you need firebase for notifcations and groups and blogs? do you need backendless, supabase, and other databases to connect you content? do you need dozens of other things like onesignal and such? NO is the answer!
with wix you get all that and messaging built right in! and its the most beautiful and easy to use database out there fully secure, and a onestop shop including a front end site!. and wix headless has opened all that to our disposal!
when you add Flutterflow to this you get some really powerful stuff at your fingertips!
below is a my functions.js code that you can set to any cms you make in wix. simply change the info and database names, and it just works, even translates the api images for you!
hope it helps you all!
rom 'wix-http-functions';
import wixData from 'wix-data';
import { fetch } from 'wix-fetch';
// Define global variables
////note: cant get pagination to work yet
/////////let nextPageNumber = 1;
////let numberOfLoadedItems = 0;
////let lastResponse = null;
////////////////////////CMS api//////////////////////////////
export function get_myFunction(request) {
// Making a common open API for your data collections in Wix Code
let whiteList = ['Name of databaseid', 'add more with commas'];
const response = {
headers: {
'Content-Type': 'application/json'
}
};
// Function to convert the Wix image URL to an external accessible URL
function convertWixImageUrl(wixImageUrl) {
if (wixImageUrl.startsWith('wix:image://v1/')) {
let convertedUrl = wixImageUrl.replace('wix:image://v1/', 'https://static.wixstatic.com/media/');
const match = convertedUrl.match(/\/([^/]+)$/);
if (match && match[1]) {
convertedUrl = convertedUrl.replace(match[0], '');
}
return convertedUrl;
} else {
return wixImageUrl;
}
}
// Function to prepend base URL to links that start with "/"
function prependBaseUrlIfNeeded(value) {
if (typeof value === 'string' && value.startsWith('/')) {
return "https://yoursiteurl.com" + value;
}
return value;
}
// Function to recursively convert Wix image URLs in an object
function convertWixImageUrlsInObject(obj) {
for (let prop in obj) {
if (typeof obj[prop] === 'string') {
obj[prop] = convertWixImageUrl(obj[prop]);
obj[prop] = prependBaseUrlIfNeeded(obj[prop]);
// Check if the property starts with "link-"
if (prop.startsWith('link-')) {
// Split the property by hyphen and remove hyphens from the second part
const parts = prop.split('-');
parts.splice(1, 1); // Remove the hyphenated part
obj[parts.join('')] = obj[prop]; // Create the new property without hyphens
delete obj[prop]; // Delete the old property
}
} else if (typeof obj[prop] === 'object') {
convertWixImageUrlsInObject(obj[prop]);
}
}
}
let datacollection = request.path[0];
if (whiteList.includes(datacollection)) {
return wixData.query(datacollection)
.limit(1000)
.ascending('title')
.find()
.then((apiResults) => {
if (apiResults.totalCount > 0) {
// Convert Wix image URLs and prepend base URL to links starting with "/"
apiResults.items.forEach((item) => {
convertWixImageUrlsInObject(item);
});
response.body = {
items: apiResults.items
};
return ok(response);
}
response.body = {
items: "No items found in the collection."
};
return ok(response);
});
}
response.body = {
error: "Data Collection is not allowed to be used through this API."
};
return badRequest(response);
}
// Function to convert the Wix image URL to an external accessible URL
function convertWixImageUrl(wixImageUrl) {
if (wixImageUrl.startsWith('wix:image://v1/')) {
let convertedUrl = wixImageUrl.replace('wix:image://v1/', 'https://static.wixstatic.com/media/');
const match = convertedUrl.match(/\/([^/]+)$/);
if (match && match[1]) {
convertedUrl = convertedUrl.replace(match[0], '');
}
return convertedUrl;
} else {
return wixImageUrl;
}
}
// Function to prepend base URL to links that start with "/"
function prependBaseUrlIfNeeded(value) {
if (typeof value === 'string' && value.startsWith('/')) {
return 'https://yoursiteurl.com' + value;
}
return value;
}
// Function to recursively convert Wix image URLs in an object
function convertWixImageUrlsInObject(obj) {
for (let prop in obj) {
if (typeof obj[prop] === 'string') {
obj[prop] = convertWixImageUrl(obj[prop]);
obj[prop] = prependBaseUrlIfNeeded(obj[prop]);
// Check if the property starts with "link-"
if (prop.startsWith('link-')) {
// Split the property by hyphen and remove hyphens from the second part
const parts = prop.split('-');
parts.splice(1, 1); // Remove the hyphenated part
obj[parts.join('')] = obj[prop]; // Create the new property without hyphens
delete obj[prop]; // Delete the old property
}
} else if (typeof obj[prop] === 'object') {
convertWixImageUrlsInObject(obj[prop]);
}
}
}
////////////////////////////////////Vpx Table api end///////////////////
here is one of my sites I'm using it on