Open AsimRamay opened 8 years ago
Hi @AsimRamay, Have you fixed your problem, I'm also trying to use socket.io ver2.0.3 with iisnode, but still can't find the socket.io/socket.io. js even though did exactly what you did. The error is : "Uncaught SyntaxError: Unexpected token <", Can you help me?
as per the original post yea i fixed it, as for helping you it would be much easier to help if you could post the code snippet your using , as all 'Uncaught SyntaxError: Unexpected token' tells me is that there is a syntax problem/ wrong formating i.e. something like Math.max(2, 42) which is correct vs Math.max(2, 42,); which is wrong for unexpected token without seeing the snippet it could basically be anything
Edit: saw your ticket, answered there
@AsimRamay What did you web.config look like?
I keep getting 404 transport=polling errors with socketio.
Another question, what exactly is path: '/hapijs/socket.io'
pointing to? The socket.io.js file?
My folder structure is:
public
socketio
socket.io.js
app.js
@ves-krd
my web.config was as follows
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<!-- Virtual Directory Setup
assign virtualDirPath below a value like '/{path}'
Add below to your app code and then prepend routes with virtualDirPath
var virtualDirPath = process.env.virtualDirPath || ''; -->
<add key="virtualDirPath" value="" />
</appSettings>
<system.webServer>
<!-- mimeMap enables IIS to serve particular file types as specified by fileExtension. -->
<staticContent>
<!--<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />-->
</staticContent>
<modules runAllManagedModulesForAllRequests="false" />
<iisnode
node_env="%node_env%"
nodeProcessCountPerApplication="1"
maxConcurrentRequestsPerProcess="1024"
maxNamedPipeConnectionRetry="100"
namedPipeConnectionRetryDelay="250"
maxNamedPipeConnectionPoolSize="512"
maxNamedPipePooledConnectionAge="30000"
asyncCompletionThreadCount="0"
initialRequestBufferSize="4096"
maxRequestBufferSize="65536"
uncFileChangesPollingInterval="5000"
gracefulShutdownTimeout="60000"
loggingEnabled="true"
logDirectory="iisnode"
debuggingEnabled="true"
debugHeaderEnabled="false"
debuggerPortRange="5058-6058"
debuggerPathSegment="debug"
maxLogFileSizeInKB="128"
maxTotalLogFileSizeInKB="1024"
maxLogFiles="20"
devErrorsEnabled="true"
flushResponse="false"
enableXFF="false"
promoteServerVars=""
configOverrides="iisnode.yml"
watchedFiles="web.config;*.js"
nodeProcessCommandLine="C:\Program Files\nodejs\node.exe" />
<handlers>
<!-- Indicates that the server.js file is a node.js web app to be handled by the iisnode module -->
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<!-- Do not interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?" />
</rule>
<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}"/>
</rule>
<!-- All other URLs are mapped to the node.js web app entry point -->
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server.js"/>
</rule>
<rule name="SocketIO" patternSyntax="ECMAScript">
<match url="socket.io" />
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>
<security>
<requestFiltering>
<hiddenSegments>
<add segment="node_modules" />
</hiddenSegments>
</requestFiltering>
</security>
<directoryBrowse enabled="false" />
</system.webServer>
</configuration>
/hapijs/socket.io
points to where the socket.io file is served on live this depends on your configuration, mine wasn't served at the root of the domain but a subfolder in the domain, its good to point to this file either way as it minimises error caused by relative pathing in nodejs (as served location is like a mini sandbox in a way)
i.e.
public
Hapijs(app root)
server.js
web.config
note socket.io does not exist here but on live its served here because this is app root location , and web config, html and js file ensure and expect the io file to be served here
@AsimRamay Awesome, thank you. I have everything up and running now, except POST requests aren't working... any ideas there?
Also, I don't know how to find the logs from the node process. There should be some errors somewhere but I checked the documentation and the directories they suggest have nothing.
@ves-krd if logging is enabled and log dir is set to default should show up in same folder as the js file as per documentation
if your application is at http://foo.com/bar.js, logs will be accessible at http://foo.com/iisnode;
works for me this way so not sure what exactly is wrong there for you
as for post requests make sure they are enabled in your iis website (by default they should be but its not always the case) i.e.
If you are using IIS 6 and lower:
From inside the IIS management screen right click on your website or virtual directory. Go to Properties then go to the Home Directory or Virtual Directory tab and click on the Configuration button. From there you can add/update extensions and what Verbs are accepted.
If you are using IIS 7:
From inside the IIS management screen click on Handler Mappings. You can add by clicking the links on the right side or double-click on an item to edit it.
as per https://stackoverflow.com/questions/3472429/how-do-i-configure-iis-to-accept-post-requests
also remember if your using my web.config you have to handle post and gets in code as I'm using hapijs in my setup as framework so my web.config redirects all urls to server.js where the post is then progmatically handled e.g.
server.route({
method: ['PUT', 'POST'],
path: '/',
handler: function (request, h) {
return 'I did something!';
}
});
hi i'm new to Nodejs , trying to setup socket.io after completing a Hapi JS tutorial no errors seem to be occurring however the server isn't serving the: /socket.io/socket.io.js file however Hapi JS api is still working perfectly and all other includes
contents of my files are as follows:
[Console] Server running at: socket:.\pipe\bef8a2e4-1e76-4039-b582-75d95d7b0990 Connected with Database
Update:
i fixed the issues , it had to do with socket.io migrating from 0.9.x being very fragmented and unclear
i went through several iterations including using attach and io.path = as stated in the docs, however the only thing that worked for me was to pass the parameters during require socket io , which was very hard to find in the docs
|_0.9.x___| [server.js] var io = require('socket.io').listen(server.listener); io.configure(function() { io.set('transports', [ 'flashsocket' , 'htmlfile' , 'xhr-polling' , 'jsonp-polling' ]); if (process.env.IISNODE_VERSION) { // If this node.js application is hosted in IIS, assume it is hosted // in IIS virtual directory named 'dante' and set up the socket.io's resource // value for socket.io to recognize requests that target it. // Note a corresponding change in the client index-socketio.html, as well // as necessary URL rewrite rule in web.config.
});
io.sockets.on('connection', function (socket) { socket.emit('news', { hello: 'world' }); socket.on('my other event', function (data) { console.log(data); }); });
[index.html] var details = { resource: (window.location.pathname.split('/').slice(0, -1).join('/') + '/socket.io').substring(1) };
|_1.4.x___| var io = require('socket.io')(server.listener, { transports: [ 'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling', 'polling' ], path: '/hapijs/socket.io' });
io.on('connection', function (socket) { socket.emit('news', { hello: 'world' }); socket.on('my other event', function (data) { console.log(data); }); });
[index.html] var details = { path: ('/'+window.location.pathname.split('/').slice(0, -1).join('/') + '/socket.io').substring(1) };