-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathconf.js
162 lines (159 loc) · 5.96 KB
/
conf.js
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
"use strict";
var path = require('path'),
fs = require('fs');
var conf = {
root: path.join(__dirname, '../../'), //服务器索引的根目录,可配置为任意本地地址
port: 80, //服务器监听端口
handle: true, //是否开启服务器动态脚本 (基本的include/belong/模板引擎/压缩功能等均依赖此配置)
runJs: true, //是否使用服务器模板引擎
uploadFile: false, //是否开启文件上传保存
middleware: true, //中间件支持, LESS/CoffeeScript 等支持
autoprefixer: false,//autoprefixer 支持
babel: false, //babel解析js
debug: true, //是否对js以及css文件进行简单压缩,debug:true表示不压缩
cdn: false, //针对线上运行服务器配置, 缓存资源到运行内存减少硬盘IO
"fs_mod": true, //是否支持文件夹列表展示
welcome: "", //使用欢迎页面的文件名,不为空时,fs_mod可能失效
notFound: path.join( __dirname , "../html/404.html" ), //访问的资源不存在时跳转的页面配置
folder: path.join( __dirname , "../html/folder.html" ), //显示文件夹列表时候的配置页面
include: "\\$include\\[[\"'\\s]*([^\"'\\s]+)[\"'\\s]*\\](\\[[\"'\\s]*([^\"'\\s]+)[\"'\\s]*\\])?",
placeholder: "$[placeholder]",
belong: "\\$belong\\[[\"\\s]*([^\"\\s]+)[\"\\s]*\\]",
livereload: false, //是否监听文件变化刷新网页, 详细配置如下
// 支持映射关联文件构建
/*
livereload: {
inject: function(pathname){
// 只在html文件中插入livereload代码
return pathname.match(/\.html/);
},
relative: function(pathname){
var root = conf.root;
if(pathname.match(/layout\.html/)){
// 如果是layout.html修改, pages文件夹下面所有管理的文件都需要修改。
return fs.readdirSync(path.join(root, 'pages'))
.map(function(filename){
return 'pages/' + filename;
});
}
}
},
*/
maxConnections: 1000, //并发处理的最大连接数
output: "c:\\output\\",
buildFilter: function(filePath){
return !/\bnode_modules|\.git\b/.test( filePath );
},
renameMap: [ // html页面中使用$rename[]的资源修改, 如果配置了withBuild属性将在构建时候对文件进行对应重命名,
/*
{
reg: /^\//, // 把绝对路径都改成带域名的
release: "http://localhost/"
},
{ // renameMap 过滤管道
// 依次匹配正则进行替换,
// 所有配置的正则都会经过,
// 最后还会附加中间件(如:less)的rename
reg: /src\/css\/([\w\-]+)/,
release: "dist/css/$1",
withBuild: true
},
{
// 添加MD5重命名文件
// 凡是添加了 withBuild 参数均被构建环节使用
reg: /^[^\\\/].*\.css$/,
withBuild: 'md5'
}
*/
],
'nginx-http-concat': true, // 支持
filter: {
get: function(/*req, resp*/){
// console.trace( arguments[0].url ); // 这个前置过滤器可以过滤所有服务端请求
}
},
agent: {}, // 代理复杂配置,匹配路径从另外服务器获取资源并可以修改响应信息
/*
agent: {
get: function(path){
if( path.match(/node-server/) ){
return {
host: "raw.githubusercontent.com",
port: 443,
setHeaders: function(headers){
delete headers['x-frame-options']
}
}
}
}
},
*/
extend: function(o){
var res = {};
for( var i in this ){
res[i] = this[i];
}
for( var j in o ){
res[j] = o[j];
}
return res;
},
expires: 0 //服务端缓存时间设置
};
exports.localhost = conf.extend({});
exports.staticconf = conf.extend({ //不要删除或者修改这个服务
port: 2850,
debug: false,
gzip: true,
cdn: true,
expires: 1000 * 60 * 60 * 24,
filter: {
get1: function(req, resp){
if( req.url.match(/^[\\\/]?(config|upload|nodeLib\/html)([\/\\])*/) ){
resp.writeHead(403,{"content-type": "text/html"});
resp.end('<h2 style="text-align:center">禁止访问</h2>');
return false;
}
}
}
});
var confPath = path.join( __dirname, "../../../conf.js" );
var stat = fs.existsSync( confPath );
if( !stat ){
fs.writeFileSync( confPath, 'exports["localhost"] = ' + JSON.stringify( {
root: conf.root,
port: conf.port,
output: conf.output
}, null, 4 ) + ';\n' );
}
try{
var $conf = require('../../../conf.js');
for(var k in $conf){
if( k === "setup" ){
exports.setup = $conf[k];
}
else if( k === "staticconf" ){
exports[k] = conf.extend.call( exports.staticconf, $conf[k] );
}else{
exports[k] = conf.extend( $conf[k] );
var f2eConfPath = path.join(exports[k].root, 'f2e-conf.js');
if (fs.existsSync(f2eConfPath)) {
try {
var currentConf = require(f2eConfPath);
var localConf = currentConf.localhost;
delete localConf.root;
exports[k] = exports[k].extend(localConf);
if(currentConf.setup) {
exports.setup = currentConf.setup;
}
}catch(e){
console.trace(e);
console.trace("配置文件语法错误!:\n" + f2eConfPath);
}
}
}
}
}catch(e){
console.trace("配置文件错误,使用默认配置!");
console.error(e);
}