waffle
Version:
シンプルなWEBアプリケーションフレームワークです。(ALL YOUR NODE ARE BELONG TO US)
87 lines (75 loc) • 2.04 kB
JavaScript
/*
* Copyright 2012 Katsunori Koyanagi
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
/**
* @overview フレームワーク向けの組み込みライブラリのパッチを行います。
*/
;
//
// fsにpathをマージし、pathのexistsを修正するパッチ
//
(function() {
var fs = require("fs");
if (fs.__patched__) {
return;
}
fs.__patched__ = true;
var path = require("path");
if (process.platform == "win32") {
var pattern = /^[a-zA-Z]\:(.*)/;
var _exists = path.exists;
path.exists = function(path, callback) {
if (path) {
pattern.lastIndex = 0;
if (pattern.test(path)) {
path = RegExp.$1;
}
}
if (path === "\\") {
callback(true);
return;
}
return _exists(path, callback);
};
var _existsSync = path.existsSync;
path.existsSync = function(path) {
if (path) {
pattern.lastIndex = 0;
if (pattern.test(path)) {
path = RegExp.$1;
}
}
if (path === "\\") {
return true;
}
return _existsSync(path);
};
}
fs.__proto__ = path;
})();
//
// ServerResponse#writeHeadをフックするためのパッチ
//
(function() {
var ServerResponse = require("http").ServerResponse;
if (ServerResponse.__patched__) {
return;
}
var writeHead0 = ServerResponse.prototype.writeHead;
ServerResponse.prototype.writeHead = function() {
this.emit("writeHead");
return writeHead0.apply(this, arguments);
};
})();