信号机自主机和静态文件服务器(例如owin.selfhost)



我的独立Singular web服务"太"成功了。我们现在想删除IIS服务器,它只提供大约10个JS/HTML/CSS文件。Node.JS有一个静态文件插件

我看了看,我发现OWIN.SelfHost的Katana也有这样的功能。http://odetocode.com/blogs/scott/archive/2014/02/10/building-a-simple-file-server-with-owin-and-katana.aspx


更新

有人建议使用OWIN.Self-Host,它有一个功能,但我不确定把它放在我现有的代码中的哪里,也不确定它是否会影响现有的SIGNALR代码(所有集线器共享相同的HTTP请求调用,所以我也在同一端口上挤入Self主机,我想知道这是否有效)。此外,使用Scott Allen的(上面引用的)例子也会很好,它也允许文件浏览。

以下是我当前用于启动SIGNALR(V2.2)的代码,该代码直接从Main.cs文件运行:

class Comm
{
    public string url = "http://localhost:7700";
    // string url = "http://*:7700"; // Requires admin privileges
    public void start()
    {
        Task t = Task.Run(() =>
        {
            WebApp.Start<Startup>(url);
            this.Clients = GlobalHost.ConnectionManager.GetHubContext<GatewayHub>().Clients;
            Console.WriteLine("Server running on {0}", url);
            Thread.Sleep(Timeout.Infinite);
        });
    }
    public void send()
    {
        Clients.All.display("broadcast sent...");
    }
    private IHubConnectionContext<dynamic> Clients
    {
        get;
        set;
    }
}
class Startup
{
    public void Configuration(IAppBuilder app)
    {
        var hubConfiguration = new HubConfiguration();
        hubConfiguration.EnableDetailedErrors = (Tools.LogLevel >= 12);
        hubConfiguration.EnableJavaScriptProxies = true;
        app.UseCors(CorsOptions.AllowAll);
        app.MapSignalR("/signalr", hubConfiguration);
    }
}

这个答案真的来自@Tracher,我希望他能把它写出来,这样我就可以信任他了。但多亏了他的投入,以下是对我有效的方法。我不需要评论行。我所需要的只是为/signlar和静态FileSystem 设置路径

}
class Startup
{
    public void Configuration(IAppBuilder app)
    {
        var hubConfiguration = new HubConfiguration();
        hubConfiguration.EnableDetailedErrors = (Tools.DebugLevel > 12);
        hubConfiguration.EnableJavaScriptProxies = true;
        app.UseCors(CorsOptions.AllowAll);
        //app.UseStaticFiles();
        app.UseFileServer(new FileServerOptions()
        {
            //RequestPath = new PathString("/Scopes"),
            EnableDirectoryBrowsing = true,
            FileSystem = new PhysicalFileSystem(@".Scopes"),
        });
        app.MapSignalR("/signalr", hubConfiguration);
    }
}

相关内容

最新更新