forked from oraoto/pib
-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
index.mjs
executable file
·53 lines (46 loc) · 1.32 KB
/
index.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/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();
response.writeHead(result.status, [...result.headers.entries()].flat());
let done = false;
while (!done)
{
const chunk = await reader.read();
done = chunk.done;
chunk.value && response.write(chunk.value);
}
response.end();
});
server.listen(3003);