Some questions about nodejs middleware framework connectivity

66 5

All right, there's a problem, please. Please, thank you.

Recently read the code for the nodejs connection framework ( portal ): A https://github.com/senchalabs/connect. See the documentation to see how coonect uses the following methods:

//由API文档明显知道,可以这样调用createServer
//HTTP
 var server = connect.createServer(
 connect.logger()
, connect.static(__dirname + '/public')
 );
//HTTPS
 var server = connect.createServer(
 { key: key, cert: cert }
, connect.logger()
, connect.static(__dirname + '/public')
 );
//或者直接:
 connect(
 connect.logger()
, connect.static(__dirname + '/public')
 ).listen(3000);

The source code for connecting to the connect knows the implementation of connect. Createserver function:

function createServer() {
 function app(req, res){ app.handle(req, res); }
 utils.merge(app, proto);
 app.stack = [];
 return app;
 };

There's no way to find out how to handle incoming parameters in this function.

Continue to trace the implementation code for its proto, only app. Use and app. Handle, and didn't find where it was called. But it would be sure that connect. Createserver ( ) returns an instance of http. In the nodejs core http lib.

My current level can only be here. ).

[ due to the lack of a nodejs environment, I'm sorry, internet cafe: ( ], so please have a nodejs environment to analyze the process, especially the process of.

- thank you! - nodejs, get out of here.

2 Answers

125 3

First of all, thank you for the @ gaosboy, thank you for your forwarding on webo. Here's a. Thank you.

Because I'm accustomed to git to clone the latest code for a repository, after all, the latest code is analyzed and compared. But this time, my basic, I.

I really didn't think I was used to the latest code for git. This is a good habit.

Finally I found 1, 7, 1, nodejs connect code, portal https://github.com/senchalabs/connect..., 看到/lib/connect.js里面的代码我立刻就知道我clone错版本的代码了!

function createServer() {
 if ('object' == typeof arguments[0]) {
 return new HTTPSServer(arguments[0], 
 ` `Array.prototype.slice.call(arguments, 1)
 );
 } else {
 return new HTTPServer(
 Array.prototype.slice.call(arguments)
 );
 }
 };

Thank you very much for answering my questions on the nodejs mailing list, and your hint is very. I'll reflect the error of this. Code, although you.

I'm sorry, I can't help everyone watch and reply.

Thank you for your attention.

Thank you.

Login sf sees a reply to @ students. Actually js, I'm still very familiar, just clone the wrong version of the code. Now the latest code for nodejs connect is still in development, and it's no longer a, code, no wonder I've. Thank you for your view! thank you.

- thank you! - thank you.

64 2

First of all, thank you for the @ gaosboy, thank you for your forwarding on webo. Here's a. Thank you.

Because I'm accustomed to git to clone the latest code for a repository, after all, the latest code is analyzed and compared. But this time, my basic, I.

I really didn't think I was used to the latest code for git. This is a good habit.

Finally I found 1, 7, 1, nodejs connect code, portal https://github.com/senchalabs/connect..., 看到/lib/connect.js里面的代码我立刻就知道我clone错版本的代码了!

function createServer() {
 if ('object' == typeof arguments[0]) {
 return new HTTPSServer(arguments[0], 
 ` `Array.prototype.slice.call(arguments, 1)
 );
 } else {
 return new HTTPServer(
 Array.prototype.slice.call(arguments)
 );
 }
 };

Thank you very much for answering my questions on the nodejs mailing list, and your hint is very. I'll reflect the error of this. Code, although you.

I'm sorry, I can't help everyone watch and reply.

Thank you for your attention.

Thank you.

Login sf sees a reply to @ students. Actually js, I'm still very familiar, just clone the wrong version of the code. Now the latest code for nodejs connect is still in development, and it's no longer a, code, no wonder I've. Thank you for your view! thank you.

- thank you! - thank you.

85 5

First answer you why createserver ( ) has no parameters and his api calls still use parameters.
It's the basics of a js. The argument to the function is executed before the function is executed. The meaning of this method is to execute connect.logger() before the connect. Createserver ( ) execution. connect.static(__dirname + '/public') It's a bit. But it's very.

connect.createServer()
. use(connect.favicon())
. use(connect.logger())
. use(connect.static(__dirname + '/public'))
. listen(3000);

You better understand.

This version of the code I haven't seen. My computer is on a 1. 7. I've compared the discovery to a great. A person thinks 1.

94 0

First answer you why createserver ( ) has no parameters and his api calls still use parameters.
It's the basics of a js. The argument to the function is executed before the function is executed. The meaning of this method is to execute connect.logger() before the connect. Createserver ( ) execution. connect.static(__dirname + '/public') It's a bit. But it's very.

connect.createServer()
. use(connect.favicon())
. use(connect.logger())
. use(connect.static(__dirname + '/public'))
. listen(3000);

You better understand.

This version of the code I haven't seen. My computer is on a 1. 7. I've compared the discovery to a great. A person thinks 1.

...