Php-Cgi-Wasm for Node.js
@todo Document this example.
#!/usr/bin/env node
import http from 'http';
import { PhpCgiNode } from 'php-cgi-wasm/PhpCgiNode.mjs';
const php = new PhpCgiNode({
prefix: '/php-wasm/cgi-bin/'
, docroot: '/persist/www'
, persist: [
mountPath: '/persist' , localPath: './persist'}
{, {mountPath: '/config' , localPath: './config'}
], sharedLibs: [
await import('php-wasm-intl')
, await import('php-wasm-libxml')
, await import('php-wasm-phar')
, await import('php-wasm-mbstring')
, await import('php-wasm-openssl')
, await import('php-wasm-dom')
, await import('php-wasm-xml')
, await import('php-wasm-simplexml')
, await import('php-wasm-sqlite')
, await import('php-wasm-zlib')
, await import('php-wasm-gd')
], types: {
jpeg: 'image/jpeg'
, jpg: 'image/jpeg'
, gif: 'image/gif'
, png: 'image/png'
, svg: 'image/svg+xml'
};
})
console.error('Open "\x1b[33mhttp://localhost:3003/php-wasm/cgi-bin\x1b[0m" in your browser...');
const server = http.createServer(async (request, response) => {
const result = await php.request(request);
const reader = result.body.getReader();
.writeHead(result.status, [...result.headers.entries()].flat());
response
let done = false;
while (!done)
{const chunk = await reader.read();
= chunk.done;
done .value && response.write(chunk.value);
chunk
}
.end();
response;
})
.listen(3003); server