1 | /**
|
2 | * @file WebServer默认配置
|
3 | * @author otakustay[otakustay@live.com],
|
4 | * errorrik[errorrik@gmail.com],
|
5 | * ostream[ostream.song@gmail.com],
|
6 | * firede[firede@firede.us]
|
7 | */
|
8 |
|
9 | // 端口
|
10 | exports.port = 8848;
|
11 |
|
12 | // server协议,默认是http,可以是https
|
13 | exports.protocol = 'http';
|
14 | // 如果protocol是https时,需要tlsOptions
|
15 | // http://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener
|
16 | exports.tlsOptions = {
|
17 | };
|
18 |
|
19 | // 网站根目录
|
20 | exports.documentRoot = process.cwd();
|
21 |
|
22 | // 当路径为目录时,是否显示文件夹内文件列表
|
23 | exports.directoryIndexes = true;
|
24 |
|
25 | // less 包含文件存放地址,可以是绝对路径,也可以是相对路径(相对于网站根目录)
|
26 | exports.lessIncludePaths = [];
|
27 |
|
28 | // 是否为 coffee-script 自动生成 sourceMap
|
29 | exports.coffeeSourceMap = true;
|
30 |
|
31 | /* handlers
|
32 | * 支持expressjs的path的写法,可以通过request.parameters来获取url中的参数
|
33 | * 如:
|
34 | * {
|
35 | * location: '/lib/:filename',
|
36 | * handler: function(context) {
|
37 | * console.log(context.request.parameters);
|
38 | * }
|
39 | * }
|
40 | *
|
41 | * 如果访问http://127.0.0.1:8848/lib/config.js
|
42 | * handler将打印出{"filename": "config.js"}
|
43 | */
|
44 | exports.getLocations = function () {
|
45 | return [
|
46 | {
|
47 | location: '/',
|
48 | handler: home('index.html')
|
49 | },
|
50 | {
|
51 | location: /^\/redirect-local/,
|
52 | handler: redirect('redirect-target', false)
|
53 | },
|
54 | {
|
55 | location: /^\/redirect-remote/,
|
56 | handler: redirect('http://www.baidu.com', false)
|
57 | },
|
58 | {
|
59 | location: /^\/redirect-target/,
|
60 | handler: content('redirectd!')
|
61 | },
|
62 | {
|
63 | location: '/empty',
|
64 | handler: empty()
|
65 | },
|
66 | {
|
67 | location: /^[^\?]+?\.css($|\?)/,
|
68 | handler: [
|
69 | autocss()
|
70 | ]
|
71 | },
|
72 | {
|
73 | location: /^[^\?]+?\.md($|\?)/,
|
74 | handler: [
|
75 | markdown()
|
76 | ]
|
77 | },
|
78 | {
|
79 | location: /^[^\?]+?\.less($|\?)/,
|
80 | handler: [
|
81 | file(),
|
82 | less()
|
83 | ]
|
84 | },
|
85 | {
|
86 | location: /^[^\?]+?\.styl($|\?)/,
|
87 | handler: [
|
88 | file(),
|
89 | stylus()
|
90 | ]
|
91 | },
|
92 | {
|
93 | location: /^[^\?]+?\.js($|\?)/,
|
94 | handler: [
|
95 | autocoffee()
|
96 | ]
|
97 | },
|
98 | {
|
99 | key: 'source',
|
100 | location: /^[^\?]+?\.coffee($|\?)/,
|
101 | handler: [
|
102 | file(),
|
103 | coffee()
|
104 | ]
|
105 | },
|
106 | {
|
107 | location: /^.*$/,
|
108 | handler: [
|
109 | file(),
|
110 | proxyNoneExists()
|
111 | ]
|
112 | }
|
113 | ];
|
114 | };
|
115 |
|
116 | exports.injectResource = function ( res ) {
|
117 | for ( var key in res ) {
|
118 | global[ key ] = res[ key ];
|
119 | }
|
120 | };
|