I am trying to run SignalR in Nancy in a console app.
When my browser does $.connection.hub.start()
it gets 404 - NotFound
for //localhost:667/negotiate?clientProtocol=1.3
----8<----
I am (trying) running Nancy on one port and SignalR on another. Nancy works with Razor. SignalR returns the hub javascript alright.
(Sorry for the amount of code below but I haven't been able to reduce it further.)
(This question might be recognized from an earlier - now deleted question that I had labeled badly.)
Client code:
<script type="text/javascript" src='/Scripts/jquery-1.6.4.min.js'></script>
<script type="text/javascript" src="/Scripts/jquery.signalR-2.0.0-beta2.js"></script>
<script src="http://localhost:667/signalr/hubs" type="text/javascript"></script>
var chat;
$(function () {
$.connection.hub.url = '//localhost:667';
$.connection.hub.logging = true;
chat = $.connection.chat;
chat.client.addMessage = onAddMessage; // declared but not here
$.connection.hub.start()
.done(function () {
alert($.connection.id);
chat.server.send('Works!');
})
.fail(function ( failreason ) {
alert( failreason );
});
});
Server code (in console program running as admin)
class Program
{
static void Main(string[] args)
{
const string webUrl = "http://localhost:666";
const string signalrUrl = "http://localhost:667";
using (var webHost = new Nancy.Hosting.Self.NancyHost(
new Uri(webUrl) ))
{
using (WebApp.Start<Startup>(signalrUrl))
{
webHost.Start();
Console.Write("Press any key");
Console.ReadKey();
webHost.Stop();
}
}
}
}
class Startup
{
public void Configuration(Owin.IAppBuilder app)
{
app.MapHubs(new HubConfiguration() { EnableCrossDomain = true });
app.UseNancy(new ApplicationBootstrapper());
}
}
public class ApplicationBootstrapper : DefaultNancyBootstrapper
{
protected override void ConfigureConventions(
Nancy.Conventions.NancyConventions nancyConventions)
{
nancyConventions.StaticContentsConventions.Add(
Nancy.Conventions.StaticContentConventionBuilder.AddDirectory(
"Scripts", @"/Scripts")
);
base.ConfigureConventions(nancyConventions);
}
}
public class Chat : Hub
{
public void Send(string message)
{
Clients.All.addMessage(message);
}
}