UNPKG

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.

37 lines 1.52 kB
/** * Serverless-optimized version that loads dependencies dynamically * This version avoids bundling large WASM files in serverless functions */ export class ServerlessPlaygroundHandler { static async getInstance(options = {}) { if (!this.instance) { this.instance = this.createInstance(options); } return this.instance; } static async createInstance(options) { try { // Dynamically import the heavy dependencies only when needed const [{ getPlaygroundHandler }, { PHPRequestHandler }] = await Promise.all([ import('./lib.js'), import('@php-wasm/universal') ]); console.log('🚀 Creating serverless Playground handler...'); const handler = await getPlaygroundHandler(options); console.log('✅ Serverless Playground handler ready'); return handler; } catch (error) { console.error('❌ Failed to create serverless handler:', error); const errorMessage = error instanceof Error ? error.message : 'Unknown error'; throw new Error(`Serverless Playground initialization failed: ${errorMessage}`); } } static async handleRequest(request, options) { const handler = await this.getInstance(options); return handler.request(request); } } ServerlessPlaygroundHandler.instance = null; export default ServerlessPlaygroundHandler; //# sourceMappingURL=serverless.js.map