Html5 pushstate Urls on ServiceStack

后端 未结 2 1659
轮回少年
轮回少年 2021-01-03 05:19

At the moment we\'re using a default.cshtml view in the root of ServiceStack to serve our AngularJS single-page app.

What I\'d like to do is enable support for html

2条回答
  •  醉酒成梦
    2021-01-03 05:57

    Expanding on my comment. This is what I ended up with trying to host an application in /app while also supporting the virtual file system.

    host.CatchAllHandlers.Add((string method, string pathInfo, string filepath) =>
    {
        if (!Regex.IsMatch(pathInfo, "^/app([/?]|$)"))
            return null;
    
        // Serve valid requests as is
        var vFile = HostContext.ResolveVirtualFile(pathInfo, null);
        if (vFile != null)
            return null;
    
        var vDir = HostContext.ResolveVirtualDirectory(pathInfo, null);
        if (vDir != null && vDir.GetDefaultDocument() != null)
            return null;
    
        // Fallback to default document
        var vDef = HostContext.ResolveVirtualDirectory("/app/", null).GetDefaultDocument();
        return new CustomResponseHandler((req, res) =>
            new HttpResult(vDef.OpenRead(), MimeTypes.GetMimeType(vDef.Name)));
    });
    

提交回复
热议问题