UNPKG

2.61 kBMarkdownView Raw
1webserver
2---------
3
4### Usage
5
6 edp webserver
7 edp webserver [--port=portNo]
8 edp webserver [--config=configFile]
9 edp webserver [--document-root=documentRoot]
10
11### Options
12
13+ --port - 启动的端口号,不指定则按照配置文件中配置的端口号启动,默认配置文件的端口配置为`8848`
14+ --config - 启动的配置文件,不指定则使用默认配置文件。
15+ --document-root - 文档根路径,不指定则使用配置文件中的文档根路径。
16
17
18### Description
19
20用于调试的WebServer。
21
22WebServer的配置是一个NodeJS风格的Javascript模块。WebServer运行时将向`配置模块`注入`资源处理方法`,并把`配置模块`嵌入运行环境中。
23
24默认的`配置文件`查找方式为:从`当前目录`向上查找,发现目录下包含`edp-webserver-config.js`文件时,将其作为`配置文件`。如果找不到`配置文件`,则以`默认配置文件`启动。
25
26
27#### 配置WebServer
28
29配置模块 *必须* 包含暴露的`injectRes`方法。
30
31```javascript
32exports.injectRes = function ( res ) {
33 for ( var key in res ) {
34 global[ key ] = res[ key ];
35 }
36};
37```
38
39配置文件允许暴露的成员如下:
40
41##### port
42
43启动端口号
44
45##### documentRoot
46
47文档根目录
48
49##### directoryIndexes
50
51是否允许显示目录内文件列表
52
53
54##### getLocations
55
56返回Location的处理器列表的方法,列表的每项是包含location和handler的Object。
57
58下面是默认的配置,供定制配置的同学参考:
59
60```javascript
61exports.getLocations = function () {
62 return [
63 {
64 location: '/',
65 handler: home( 'index.html' )
66 },
67 {
68 location: '/v3/api/detail/:id',
69 handler: function(context) {
70 console.log(context.parameters);
71 }
72 },
73 {
74 location: /^\/redirect-local/,
75 handler: redirect('redirect-target', false)
76 },
77 {
78 location: /^\/redirect-remote/,
79 handler: redirect('http://www.baidu.com', false)
80 },
81 {
82 location: /^\/redirect-target/,
83 handler: content('redirectd!')
84 },
85 {
86 location: '/empty',
87 handler: empty()
88 },
89 {
90 location: /\.less$/,
91 handler: [
92 file(),
93 less()
94 ]
95 },
96 {
97 location: /^.*$/,
98 handler: [
99 file(),
100 proxyNoneExists('www.baidu.com', 80)
101 ]
102 }
103 ];
104};
105```
106