Hello!
To help me build my plugin in VS Code, I was trying to create a ‘mock frontend’, i.e. another js file that can supply the properties and context.request() method to my server plugin file, since my plugin will be making API calls.
Is this the right approach? I am trying to use fetch() in the mock JS front end to provide the functionality of context.request() but can’t get it to work at all! Here’s the file:
export const properties = {
property1: “some value”,
property2: “another value”
}
export const context = {
request: async (requestStruct) => {
let respJ = await fetch(requestStruct.uri, {
method: requestStruct.method,
headers: requestStruct.headers,
body: requestStruct.body
});
let respR = await respJ.json();
console.log(JSON.stringify(respR));
return respR;
}
}
The console.log prints the correct fetch response to the log, But I can’t for the life of me get that response into my main plugin js function - it just shows up as undefined. I first import using:
import {properties, context} from ‘./frontEndMockUp.js’;
Then try to do the POST request using:
result = context.request(requestStructure);
Do I need another await in my plugin js function, that I then remove later?
Any help appreciated! (I’m a beginner in JS)
Edit: the result = context.request(requestStructure) works in my live Bubble plugin perfectly, so I just need to get it working in VS Code so I can continue development there.