last day (15 days later) » 

6:04 PM
-1
A: the tty.js shell does not render when I make its initialization contingent on an HTTP request

ariel_556it's because you are not returnig anything and then the browser is polling this until it return something. this.app.get("/hola", function(req, res) { res.writeHead(200, {'content-type':'text/html'}); res.end('/*html code here*/'); });

 
TypeError: Object #<IncomingMessage> has no method 'writeHead'
 
if you are using express it is not necesary to use https.createServe()
 
Sorry, my bad. It was a mistake. Now it loads, but the page is empty. ` this.get("/hola", function(req, res) { res.writeHead(200, {'content-type':'text/html'}); res.end(self.init()); });`
 
@user2979409 self.init() does not return anything. It is therefore correct that sending an HTTP message with the the return value of self.init() (which, again, has no specified return value, so it defaults to undefined) sends an empty message. If you want to have your code send something, have self.init() return something, or call res.send from inside your self.init() calls.
 
self.init() returns a lot of things when it is called outside app.get(...). self.init() calls functions that, in turn, call other functions. Finally, I get an output. The problem is that with app.get, it does not work.
 
6:04 PM
@user2979409 "self.init() returns a lot of things" It doesn't, because it doesn't have a return statement. It may print a lot to a console, or perform many other side-effect actions, but it does not return anything. The value of a function expression call like self.init() is the return value of the function being called.
 
@apsillers, and why I see a bash console "printed" in my browser, if it does not return anything? (self.init called outside app.get(...). What I want is the same output calling self.init or calling app.get('/', function() {self.init()});
 
i disagree. but i think that in this case i don't see what those methods are doing because you are not setting them: if (this.conf.localOnly) this.initLocal(); this.initMiddleware(); this.initRoutes(); this.initIO();
 
@user2979409 What does a function's return value have to do with the side-effect action of printing to a console? If you don't call return, there's no defined return value. You can call console.log in a function and not call return in that function. (For example, define a function: function foo() { console.log("I'm a log statement!"); } and then call it: var result = foo(); When you log the value of result, note that it is undefined. the return value has nothing to do with anything else the function does.)
 
@apsillers, even calling return, it does not work.
 
@user2979409 What you want to do is replace the current console-logging logging behavior with HTTP response-writing behavior. Find the function that writes to the console and replace it with a function that writes to an HTTP response. (Re: "even calling return, it does not work", what are you returning? If you return 5;, then you will write an HTTP response that contains the message 5. If you return "foo", the message will be foo. If you return something() then the message will be whatever something returns.)
 
6:04 PM
@ariel_556, this code is part of github.com/chjj/tty.js/blob/master/lib/tty.js
 
the thing is that you aren't using wisely this code: function iniciar() { self.init(); }
 
@apsillers, I return a function that should give something to the screen, and it does when calling it outside app.get. It is not so complicated to understand.
 
@user2979409 And it still does output to the console in either case, doesn't it? It doesn't matter whether you include self.init() inside of app.get or not; the behavior is identical, right? You actually want the behavior to change when you put it inside of app.get (i.e., you expect an HTTP response to be sent to your browser instead of a console message written to your bash console). Writing to a console and sending an HTTP response are different actions; you can change your code to do one instead of the other, but you'll need to change how the code sends messages.
 
in this case if you want to execute any of those methods in init(); you could call them this.app.get("/hola", function(req, res) { res.writeHead(200, {'content-type':'text/html'}); res.end(that.initLocal()); });
 
the behaviour IS NOT IDENTICAL, @apsillers. Outside app.get, I get a terminal "printed" in my screen, in my BROWSER. Inside app.get, it never loads.
it does not work, @ariel_556, that is not defined.
 
6:04 PM
@user2979409 I see; by "bash console" I assumed you meant OS-level instance of the console program bash that was running your node.js script. I see now that you mean something entirely different.
 
@user2979409 It would clarify matters greatly to edit your question to explain precisely how the behavior differs from expected behavior. For a start, include that link in your question, and go on to edit the question the information that we've pulled out here in the comments. Your actual problem is non-obvious to potential answerers, in part because it's ambiguous what you meant by "bash shell" (instead, you should say "the tty.js shell does not render when I make its initialization contingent on an HTTP request" or similar).
 

last day (15 days later) »