I have an ASP.NET MVC 5 application and a NodeJs (Express+Socket.IO) application. In business scenario, I have to run NodeJS application inside an MVC application as a sub-directory.
for. e.g,
MVC: http://foo.com NodeJS: http://foo.com/node
I have hosted both applications in IIS 8 using IISNode(Latest version). Both application utilize websockets. Asp.net application utilizes SignalR and NodeJS utilizing Socket.IO.I have followed documentation available at https://github.com/tjanczuk/iisnode .
Issue is when socket.io.js loads on client side and tries to connect to server it returns 404-Not Found result. I have attached web.config for both applications and server.js of Node application. I suspect issue is with url rewriting.
here is server.js
// Load required modules
var http = require("http"); // http server core module
var express = require("express"); // web framework external module
var io = require("socket.io"); // web socket external module
var easyrtc = require("easyrtc"); // EasyRTC external module
var request = require("request");
var consolidate = require('consolidate');
var https = require('https');
var fs = require('fs');
var options = {key: fs.readFileSync("easyrtc-key.pem"),cert: fs.readFileSync("easyrtc-cert.pem")};
// Setup and configure Express http server. Expect a subfolder called "static" to be the web root.
var httpApp = express();
var webrtcController = require('./app/controllers/webrtcController');
httpApp.route('/rtc/webrtc/index').get(webrtcController.index);
httpApp.route('/rtc/webrtc/screensender').get(webrtcController.screenSender);
httpApp.route('/rtc/webrtc/screenreceiver').get(webrtcController.screenReceiver);
httpApp.use('/rtc',express.static(__dirname + "/static/"));
httpApp.engine('html',consolidate['swig']);
httpApp.set('view engine', 'html');
httpApp.set('views', './app/views');
// Start Express http server on port 8080
var webServer = http.createServer(httpApp).listen(process.env.PORT || 1234);
// Start Socket.io so it attaches itself to Express server
var socketServer = io.listen(webServer, {"log level":1});
// Start EasyRTC server
var rtc = easyrtc.listen(httpApp, socketServer);
For MVC application web.config is standard auto generated config file.
Below is my web.config of NodeJs application.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="myapp">
<match url="node/*" />
<action type="Rewrite" url="server.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
And below is the code for connecting to socket io.
self.webSocket = io.connect(serverPath, {
'connect timeout': 10000,
'force new connection': true,
resource: 'node/socket.io'
});
All files from NodeJs application are loaded correctly, but somehow I am not able to connect to websocket.