superche
superche

Reputation: 773

Node.js serve as a backend server for frontend app

I want to use Node.js run as a back-end server to serve front-end socket.io request.

The samples I found, seems can only run pages from Node.js server.

<script src="/socket.io/socket.io.js"></script>

The above js include is served by Node.js, how to include it if the front-end is a different application (e.g. PHP or static pages) ? Do I need to include all the dependent socket.io js libraries to make it work?

Upvotes: 0

Views: 1501

Answers (2)

Ray
Ray

Reputation: 370

I'm currrently running apache/php alongside node.js/socket.io If this is what you're trying to do, you can do it by serving socket.io on a different port than what apache is serving on (assumed 80).

In node.js, initialize the socket.io listener on a port 8080 for example:

var io = require('socket.io').listen(8080);

I believe, by default, socket.io will also serve its static client side files conveniently for you, such that in you html, you can:

<script src="http://yourhost:8080/socket.io/socket.io.js"></script>

Hope that helps.

Upvotes: 2

Lyth
Lyth

Reputation: 2201

It all depends on your server configuration. You may choose a path to Node.js backend that is not used by any other resource, and configure your web-server to serve everything else.

E.g. for Apache I used ProxyPass directive to enable connections to a local Node.js on a different port (to bypass local port restrictions), though may be not an option for your purposes:

ProxyPass /help/server/ http://localhost:8002/ connectiontimeout=1500ms

Upvotes: 0

Related Questions