forked from oraoto/pib
-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathindex.mjs
More file actions
executable file
·86 lines (78 loc) · 3.62 KB
/
Copy pathindex.mjs
File metadata and controls
executable file
·86 lines (78 loc) · 3.62 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env node
import http from 'node:http';
import { PhpCgiNode } from 'php-cgi-wasm/PhpCgiNode.mjs';
const libType = process.env.LIB_TYPE ?? process.env.BUILD_TYPE ?? 'dynamic';
const sharedLibs = [];
if(libType === 'dynamic')
{
sharedLibs.push(
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')
);
}
else if(libType === 'shared')
{
sharedLibs.push(
{name: 'libxml2.so', url: new URL('node_modules/php-wasm-libxml/libxml2.so', import.meta.url)},
{name: 'libz.so', url: new URL('node_modules/php-wasm-zlib/libz.so', import.meta.url)},
{name: 'libzip.so', url: new URL('node_modules/php-wasm-libzip/libzip.so', import.meta.url)},
{name: 'libfreetype.so', url: new URL('node_modules/php-wasm-gd/libfreetype.so', import.meta.url)},
{name: 'libjpeg.so', url: new URL('node_modules/php-wasm-gd/libjpeg.so', import.meta.url)},
{name: 'libwebp.so', url: new URL('node_modules/php-wasm-gd/libwebp.so', import.meta.url)},
{name: 'libpng.so', url: new URL('node_modules/php-wasm-gd/libpng.so', import.meta.url)},
{name: 'libiconv.so', url: new URL('node_modules/php-wasm-iconv/libiconv.so', import.meta.url)},
{name: 'libicuuc.so', url: new URL('node_modules/php-wasm-intl/libicuuc.so', import.meta.url)},
{name: 'libicutu.so', url: new URL('node_modules/php-wasm-intl/libicutu.so', import.meta.url)},
{name: 'libicutest.so', url: new URL('node_modules/php-wasm-intl/libicutest.so', import.meta.url)},
{name: 'libicuio.so', url: new URL('node_modules/php-wasm-intl/libicuio.so', import.meta.url)},
{name: 'libicui18n.so', url: new URL('node_modules/php-wasm-intl/libicui18n.so', import.meta.url)},
{name: 'libicudata.so', url: new URL('node_modules/php-wasm-intl/libicudata.so', import.meta.url)},
{name: 'libcrypto.so', url: new URL('node_modules/php-wasm-openssl/libcrypto.so', import.meta.url)},
{name: 'libssl.so', url: new URL('node_modules/php-wasm-openssl/libssl.so', import.meta.url)},
{name: 'libonig.so', url: new URL('node_modules/php-wasm-mbstring/libonig.so', import.meta.url)},
{name: 'libsqlite3.so', url: new URL('node_modules/php-wasm-sqlite/libsqlite3.so', import.meta.url)},
{name: 'libtidy.so', url: new URL('node_modules/php-wasm-tidy/libtidy.so', import.meta.url)},
{name: 'libyaml.so', url: new URL('node_modules/php-wasm-yaml/libyaml.so', import.meta.url)},
);
}
const php = new PhpCgiNode({
version: process.env.PHP_VERSION ?? '8.3'
, sharedLibs
, prefix: '/php-wasm/cgi-bin/'
, docroot: '/persist/www'
, persist: [
{mountPath: '/persist' , localPath: './persist'}
, {mountPath: '/config' , localPath: './config'}
]
, 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);