Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle HTTP upgrade in ExpressJS?

The newest ExpressJS doesn't inherit from http.Server anymore.

If I try to listen on the upgrade event, the server will answer with a 404 Not Found.

Current [simplified] code is:

app.on('upgrade', function(req, socket, head) { /* ... */ });

If I try to search for the answer on Google, I'll only find links related to "3.0 -> 4.0 express upgrade", not HTTP upgrade.

EDIT:

As requested by @jfriend00 , my express initialization [simplified] code:

app = express.createServer();
app.listen(self.port, self.ipaddress);
like image 360
vinipsmaker Avatar asked Feb 23 '15 03:02

vinipsmaker


People also ask

Is the HTTP method used in Express JS?

In order to view your project, you can send information from your Express server through a GET request, an HTTP method. In index. js , append .

Does ExpressJs use http2?

express : Express is a Node. js framework for building web applications and backend APIs. spdy : spdy is an express compatible module that creates HTTP/2 enabled servers in Node. js.

Does Express need HTTP?

Express is made on top of the HTTP module. HTTP module provides various tools (functions) to do things for networking like making a server, client, etc. Express along with what HTTP does provide many more functions in order to make development easy.

Is Express server HTTP server?

The Express philosophy is to provide small, robust tooling for HTTP servers, making it a great solution for single page applications, web sites, hybrids, or public HTTP APIs. Navigate to the port 3000 as previously set in the server.


1 Answers

Since my comment seemed to work for you, I'll put it in an answer.

express.createServer() has been deprecated for a long time and removed from Express 4. You would create the app object in Express 4 with:

var app = express()

The http server object is then returned from

var server = app.listen(...)

If you need direct access to the http server object.

like image 197
jfriend00 Avatar answered Oct 06 '22 08:10

jfriend00