-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.d.ts
114 lines (88 loc) · 2.48 KB
/
index.d.ts
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
export type Options = {
/**
The port on which you want to access the webserver.
Specify `0` to use a random port.
@default 0
*/
readonly port?: number;
/**
The hostname the server will use.
Use `'0.0.0.0'` if you want it to be accessible from the outside.
@default '127.0.0.1'
*/
readonly hostname?: string;
/**
The directory the server will serve from.
@default '.'
*/
readonly base?: string;
/**
Open the server URL in the browser.
Can be one of the following:
- `true`: Opens the default server URL (`http://${hostname}${port}`).
- A relative URL: Opens that URL in the browser. Useful when testing pages that are not the default.
@default false
*/
readonly open?: boolean | string;
/**
Set environment variables for the PHP process.
*/
readonly env?: Record<string, string>;
/**
Optionally specify the path to a [router script](https://php.net/manual/en/features.commandline.webserver.php#example-412) that is run at the start of each HTTP request. If this script returns `false`, the requested resource is returned as-is. Otherwise, the script's output is returned to the browser.
Example router script:
```php
<?php
// router.php
if (preg_match('/\.(?:png|jpg|jpeg|gif)$/', $_SERVER["REQUEST_URI"])) {
return false; // Serve the requested resource as-is
} else {
echo "<p>Thanks for using php-server :)</p>";
}
?>
```
*/
readonly router?: string;
/**
The path to the PHP binary.
@default 'php'
*/
readonly binary?: string;
/**
A path to a custom [`php.ini` config file](https://php.net/manual/en/ini.php).
Default: The built-in `php.ini`
*/
readonly ini?: string;
/**
Add custom [INI directives](https://php.net/manual/en/ini.list.php).
*/
readonly directives?: Record<string, string>;
};
export type Server = {
/**
The [`subprocess.stderr`](https://nodejs.org/api/child_process.html#child_process_subprocess_stdout).
*/
readonly stdout: NodeJS.WritableStream;
/**
The [`subprocess.stderr`](https://nodejs.org/api/child_process.html#child_process_subprocess_stderr).
*/
readonly stderr: NodeJS.WritableStream;
/**
The URL to the server.
*/
readonly url: string;
/**
A method, which when called, stops the server.
*/
stop(): void;
};
/**
Start a [PHP server](https://php.net/manual/en/features.commandline.webserver.php)
@example
```
import phpServer from 'php-server';
const server = await phpServer();
console.log(`PHP server running at ${server.url}`);
```
*/
export default function phpServer(options?: Options): Promise<Server>;