wordpress-playground-handler
Version:
A Node.js library for creating and managing WordPress Playground instances with PHP request handling capabilities. Optimized for Node.js runtime environments.
46 lines • 1.7 kB
JavaScript
/**
* Lightweight version for Node.js serverless deployment
* Uses external WordPress instances instead of bundling heavy WASM files
*/
export class LightweightPlaygroundHandler {
constructor(options = {}) {
// Use a hosted WordPress instance instead of local WASM
this.wordpressUrl = options.wordpressUrl || 'https://playground.wordpress.net';
this.authToken = options.authToken;
}
async request(request) {
const fullUrl = `${this.wordpressUrl}${request.url}`;
const headers = {
'Content-Type': 'application/json',
...request.headers
};
if (this.authToken) {
headers['Authorization'] = `Bearer ${this.authToken}`;
}
try {
const response = await fetch(fullUrl, {
method: request.method,
headers,
body: request.body ? JSON.stringify(request.body) : undefined
});
const data = await response.json();
return {
httpStatusCode: response.status,
headers: Object.fromEntries(response.headers.entries()),
bytes: new TextEncoder().encode(JSON.stringify(data)),
text: JSON.stringify(data),
json: data
};
}
catch (error) {
console.error('Lightweight handler error:', error);
throw error;
}
}
}
// Lightweight version of getPlaygroundHandler
export async function getLightweightPlaygroundHandler(options = {}) {
return new LightweightPlaygroundHandler(options);
}
export default LightweightPlaygroundHandler;
//# sourceMappingURL=lightweight.js.map