Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beginner level error: done is not defined #21

Open
ghost opened this issue Jul 18, 2016 · 2 comments
Open

Beginner level error: done is not defined #21

ghost opened this issue Jul 18, 2016 · 2 comments

Comments

@ghost
Copy link

ghost commented Jul 18, 2016

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
@ghost ghost changed the title Beginner level error: done() is not defined Beginner level error: done is not defined Jul 18, 2016
@nicu
Copy link

nicu commented Jul 18, 2016

proxy.listen(validPort, done);

you are calling this function but it doesn't seem to be defined in your code.

@ghost
Copy link
Author

ghost commented Jul 19, 2016

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant