yakbak
yakbak copied to clipboard
Beginner level error: done is not defined
Hello, I am a beginner in nodejs and require some help regarding the usage of yakbak. Hope, you don't mind :-)
Situation:
At present, I develop ASP.NET webmethods via Visual studio and manually test them. Once I start a visual studio project, the test url becomes: http://localhost/<random-but-valid-port-number>
. This link can be opened via any web browser (e.g. chrome, firefox), for which I think node modules can use it also.
Code I tried:
I have started the visual studio project, and it has started on port 52280. Therefore, going to http://localhost/WebService1.asmx/Ping
yields a valid timestamp (code written by me which I want to test). Code I have written in index.js
:
// Contents of index.js
try {
var yakbak = require('yakbak');
var http = require('http');
var validPort = 52280;
var proxy = http.createServer(yakbak('http://api.example.com', {
dirname: __dirname
}));
proxy.listen(validPort, done);
var options = {
host: 'http://localhost',
port: validPort,
path: '/WebService1.asmx/Ping'
};
http.get(options, function (resp) {
resp.on('data', function (chunk) {
console.log(chunk);
});
}).on("error", function (e) {
console.log("Got error: " + e.message);
});
} catch (e) {
console.log(e.message);
console.trace();
}
Example
If I try 'WebService1.asmx/Ping' then I would expect 2016-07-18T15:50:04.483+06:00
(current timestamp) as response and this response should be cached so that if I call this url later, then I will get the cached response instead of current timestamp.
Desired output
I want to control the variable options
(i.e. path) and fetch response from that particular path. Then, I will compare the result in resp.on which will be same as the example output above. I expect yakbak to mock/cache the response.
Actual output
$ node index.js
done is not defined
Trace
at Object.<anonymous> (C:\Test\index.js:28:13)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Function.Module.runMain (module.js:575:10)
at startup (node.js:159:18)
at node.js:444:3
proxy.listen(validPort, done);
you are calling this function but it doesn't seem to be defined in your code.
You are right, afternoon bug :-(
However, I fixed the line and tried again. But got this error: listen EACCES 0.0.0.0:52280
. So, I think yakbak's proxy (i.e. nodejs proxy) is not able to listen to the visual studio project's port.
Then, I wonder, how browsers are able to listen to that port?