Skip to content

Commit

Permalink
misc: proxy bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
elcarim5efil committed Feb 13, 2017
1 parent 5ac549e commit 7920be0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/mock/modules/proxy_mock/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

var proxyConf = fozy.__config.mock.proxy;

module.exports = function (option, type) {
if (typeof option === 'string') {
option = {
Expand All @@ -17,6 +19,12 @@ module.exports = function (option, type) {
}
var _proxy = _httpProxy2.default.createProxyServer(option);

_proxy.on('proxyReq', function (proxyReq, req, res) {
if (proxyConf.host) {
proxyReq.setHeader('Host', proxyConf.host);
}
});

var doProxy = function doProxy(ctx) {
var req = ctx.req,
res = ctx.res;
Expand Down
36 changes: 36 additions & 0 deletions npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
0 info it worked if it ends with ok
1 verbose cli [ 'D:\\ProgramFiles\\nodejs\\node.exe',
1 verbose cli 'C:\\Users\\hzwuziran\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'compile' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'precompile', 'compile', 'postcompile' ]
5 info lifecycle [email protected]~precompile: [email protected]
6 silly lifecycle [email protected]~precompile: no script for precompile, continuing
7 info lifecycle [email protected]~compile: [email protected]
8 verbose lifecycle [email protected]~compile: unsafe-perm in lifecycle true
9 verbose lifecycle [email protected]~compile: PATH: C:\Users\hzwuziran\AppData\Roaming\npm\node_modules\npm\bin\node-gyp-bin;E:\github\fozy\node_modules\.bin;C:\ProgramData\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;D:\ProgramFiles\nodejs\;C:\Program Files\Git\cmd;D:\ProgramFiles\Java\jdk1.8.0_102\bin;D:\ProgramFiles\Java\jdk1.8.0_102\jre\bin;C:\Program Files\OpenVPN\bin;D:\ProgramFiles\CodingTools\apache-maven-3.3.9\bin;C:\windows\System32\WindowsPowerShell\v1.0\;D:\ProgramFiles\Yarn\bin;D:\ProgramFiles\CodingTools\apache-maven-3.3.9\bin;C:\Users\hzwuziran\AppData\Local\Programs\Python\Python35-32\Scripts\;C:\Users\hzwuziran\AppData\Local\Programs\Python\Python35-32\;C:\Users\hzwuziran\AppData\Local\atom\bin;C:\Users\hzwuziran\AppData\Roaming\npm;d:\ProgramFiles\CodingTools\Microsoft VS Code\bin
10 verbose lifecycle [email protected]~compile: CWD: E:\github\fozy
11 silly lifecycle [email protected]~compile: Args: [ '/d /s /c', 'babel -d lib/ src/ --watch' ]
12 verbose stack Error: kill ENOSYS
12 verbose stack at exports._errnoException (util.js:873:11)
12 verbose stack at process.kill (node.js:777:15)
12 verbose stack at process.listener (C:\Users\hzwuziran\AppData\Roaming\npm\node_modules\npm\node_modules\npmlog\node_modules\gauge\node_modules\signal-exit\index.js:86:15)
12 verbose stack at emitNone (events.js:72:20)
12 verbose stack at process.emit (events.js:166:7)
12 verbose stack at processEmit (C:\Users\hzwuziran\AppData\Roaming\npm\node_modules\npm\node_modules\npmlog\node_modules\gauge\node_modules\signal-exit\index.js:146:32)
12 verbose stack at processEmit (C:\Users\hzwuziran\AppData\Roaming\npm\node_modules\npm\node_modules\npm-registry-client\node_modules\npmlog\node_modules\gauge\node_modules\signal-exit\index.js:146:32)
12 verbose stack at Signal.wrap.onsignal (node.js:804:46)
13 verbose cwd E:\github\fozy
14 error Windows_NT 6.1.7601
15 error argv "D:\\ProgramFiles\\nodejs\\node.exe" "C:\\Users\\hzwuziran\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "compile"
16 error node v4.4.7
17 error npm v4.0.5
18 error code ENOSYS
19 error errno ENOSYS
20 error syscall kill
21 error kill ENOSYS
22 error If you need help, you may report this error at:
22 error <https://github.com/npm/npm/issues>
23 verbose exit [ 1, true ]
7 changes: 7 additions & 0 deletions src/mock/modules/proxy_mock/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict';

import proxy from 'http-proxy';
let proxyConf = fozy.__config.mock.proxy;

module.exports = (option, type) => {
if(typeof option === 'string') {
Expand All @@ -10,6 +11,12 @@ module.exports = (option, type) => {
}
}
let _proxy = proxy.createProxyServer(option);

_proxy.on('proxyReq', function(proxyReq, req, res){
if(proxyConf.host) {
proxyReq.setHeader('Host', proxyConf.host);
}
});

let doProxy = (ctx) => {
let req = ctx.req,
Expand Down

0 comments on commit 7920be0

Please sign in to comment.