SquishIt
SquishIt copied to clipboard
SignalR + NancyFX + Self-Hosting - HttpContext
I'm attempting to use AddDynamic with the ~/signalr/hubs path, but since this is a NancyFX project there is no HttpContext. I attempted to use AddRemote, but SquishIt turns my relative path into signalr/hubs which gets appended onto whichever subdirectory it is in rather than the site root. Is there any way to work around this?
If Nancy hasn't changed dramatically i suspect this will help.
http://blogs.lessthandot.com/index.php/webdev/serverprogramming/squishit-and-nancy-part-deux/
If not let me know I haven't tried this particular combination.
My implementation of your example only appears to make things worse. I found that your original implementation of PathTranslator did all of the regular links correct, it's just the dynamic ones I am having issues with. However, when I copied your code and modified it so that it left http links alone so that I can map directly to http://mysite/signalr/hubs I encounter an error elsewhere in Squishit in FileSystemResolver:
public string Resolve(string file)
{
return Path.GetFullPath(file);
}
The error indicates that "URI formats are not supported." with Path
Hmm OK this is definitely a gap. There's a method called BuildAbsolutePath that uses HttpContext directly, it should probably get its information from the path translator or simliar.
I will try to look into this in the near future, if you could upload a sample project somewhere that would be very helpful.
The URI formats are not supported message - assuming you are trying to use add which assumes you are adding a normal file. You will want to use AddRemote("~/signalr/hubs", "http;//mysite/signalr/hubs", true) as a workaround - this is what AddDynamic uses under the hood
https://github.com/jetheredge/SquishIt/blob/master/SquishIt.Framework/Base/BundleBase.cs#L246-250
If you get a chance to throw together a sample project I would really like to see it so I can ensure the change to that BuildAbsolutePath method works. I am not going to make the change otherwise, because I envision it as a breaking change for anyone who is already using Nancy + SquishIt (new method and possibly a rename of the IPathTranslator interface).
Email is alex dot ullrich at gmail if you don't want to upload the project here.
I am working on a sample project for your use by cutting down my current project to a functioning example
Fantastic, thanks!
Once you have a path provider in place, does
AddRemote("~/signalr/hubs", "http://mysite/signalr/hubs", true)
Work in the meantime?
I remembered I had a test project to get things working with SignalR, the initial way I did things was slightly different (though I think what I have above might be more correct?)
.AddRemote(null, HttpContext.Current.Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped) + "/signalr/hubs", true)
https://github.com/AlexCuse/PlayR/blob/7643f5f900adf01310d46f645fa615cc3296b88d/PlayR/Views/Chat/Index.cshtml#L15
Not sure if poking around in there will help or not since its not using Nancy, but it might glean some other useful info I've forgotten
Passing Null into .AddRemote and adding .ForceRelease() does not make SquishIt happy. When ResolveAppRelativePathToFileSystem(string file) is called file == null. When I try returning the null back to SqushIt from the NancyPathTranslator, SquishIt FileSystemResolver.Resolve throws an error.
When I attempt calling AddRemote as follows: AddRemote("~/signalr/hubs", "http://mysite/signalr/hubs", true) It generates: script type="text/javascript" src="signalr/hubs" Which will not work on http://site/subdirectory/signalr/hubs as the route is mapped to http://site/signalr/hubs
In addition, using the NancyPathTranslator produces links to the other files as follows: .Add(@"~/Content/scripts/knockout-3.3.0.js")=> script type="text/javascript" src="Content/scripts/knockout-3.3.0.jsD:/work/ether/etherSite/EtherSite/bin/Debug/Content/scripts/knockout-3.3.0.js"
I made a change so that AddDynamic will use the IPathTranslator interface. Method it consumes is called BuildAbsolutePath.
You can try with the package available here to see if it works: http://www.nuget.org/packages/SquishIt/0.9.8.1-alpha2
You are mostly going to be on your own figuring out the nancy issues. I do not use nancy for anything, and debugging it is more than I have time for at the moment. Injecting nancy's root path provider into your translator should give you all you need but I really have no idea. With all the translation activity now confined to that interface you should be able to figure it out by debugging your implementation. I will try updating my nancy sample project again sometime soon, but it could be a while.
I thought of another potential issue with nancy deployments today. SquishIt's bundle cache is backed by HttpRuntime.Cache which would obviously not be available.
I will try to get that hidden behind an interface but its another thing that I have no idea how to replace in Nancy. Going to reach out to a few people to see if they'd be willing/able to help with a push to fix this kind of thing for v1.0 - I would really like to put out a SquishIt.Nancy package that has implementations of all the relevant interfaces but I'm not sure I'm up to the task. Let me know if this is something you'd have the bandwidth to help with over the next few months.
I'm currently working on #315 and will take a look at this when @AlexCuse accepts the PR.