ServiceStack Self host static file paths

Hi,

I have a self host web server, I am having issues loading static content for the web page. Is there a event that I can signup to that can give me the hint to what path ServiceStack is trying to load the file from?

Thanks

There’s no event, but ServiceStack is just going to try serve the file from:

var file = HostContext.ResolveVirtualNode(httpReq.PathInfo, httpReq);

Which you can potentially simulate by hijacking the request and returning the StaticFileHandler yourself:

appHost.RawHttpHandlers.Add(req => MyShouldHandleRequest(req) 
    ? new StaticFileHandler(req.GetVirtualNode())
    : null
);

For some reason StaticFileHandler can’t find the files in the debug directory. The path to the files is correct but still none of the files are returned.

See if you have [any StartupErrors in ?debug=requestinfo][1], also the VirtualPathProvider should show the path the FileSystemVirtualPathProvider is configured to look at.

Something else you can try is [changing the physical path][2] to look at your project folder (instead of the /bin folder where it’s run), e.g:

SetConfig(new HostConfig {
#if DEBUG
    DebugMode = true,
    WebHostPhysicalPath = "~/../..".MapServerPath(),
#endif
});
```


  [1]: http://docs.servicestack.net/debugging#request-info
  [2]: http://docs.servicestack.net/self-hosting#serve-static-files-from-your-project-path

My static files are in …\bin\debug\app\ folder, In console I see that the message is that WARN: Static File ‘/app/index.api.js’ not found in path: /app/index.api.js.

FileSystemVirtualPathProvider: C:\SomeService\bin\Debug

What could be wrong?

here is debug data if that helps

{
“Usage”:“append ‘?debug=requestinfo’ to any querystring. Optional params: virtualPathCount”,
“Host”:"_v4.58_SomeService",
“HostType”:“SelfHost (AppHost)”,
“StartedAt”:“2017-05-09 03:11:11”,
“Date”:“2017-05-09 03:14:22”,
“ServiceName”:“SomeService”,
“HandlerFactoryPath”:“SomeService”,
“UserHostAddress”:"::1",
“HttpMethod”:“GET”,
“PathInfo”:"/",
“ResolvedPathInfo”:"/",
“StripApplicationVirtualPath”:true,
“GetPathUrl”:“http://localhost/SomeService”,
“AbsoluteUri”:“http://localhost/SomeService?debug=requestinfo”,
“ApplicationBaseUrl”:“http://localhost/SomeService”,
“ResolveAbsoluteUrl”:“http://localhost/SomeService/resolve”,
“RootDirectoryPath”:“C:\SomeService\bin\Debug”,
“CurrentDirectory”:“C:\SomeService\bin\Debug”,
“RawUrl”:"/SomeService?debug=requestinfo",
“Status”:0,
“ContentLength”:0,
“Headers”:{
“DNT”:“1”,
“Connection”:“Keep-Alive”,
“Accept”:“text/html, application/xhtml+xml, image/jxr, /”,
“Accept-Encoding”:“gzip, deflate”,
“Accept-Language”:“en-US,en;q=0.5”,
“Cookie”:“ss-pid=DxA097v2agyJKldOdqxh; ss-opt=temp; X-UAId=0”,
“Host”:“localhost”,
“User-Agent”:“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063”
},
“QueryString”:{
“debug”:“requestinfo”
},
“FormData”:{

},
“AcceptTypes”:[
“text/html”,
“application/xhtml+xml”,
“image/jxr”,
/
],
“OperationName”:“SomeService”,
“ResponseContentType”:“text/html”,
“RequestAttributes”:“Localhost, InSecure, HttpGet”,
“Ipv4Addresses”:“XXX.XXX.XXX.XX/255.255.0.0, 192.168.1.43/255.255.255.0, XXX.XXX.XXX.XX/255.255.0.0, 127.0.0.1/255.0.0.0”,
“Ipv6Addresses”:"",
“DebugString”:"",
“PluginsLoaded”:[
“HtmlFormat”,
“CsvFormat”,
“MarkdownFormat”,
“PredefinedRoutesFeature”,
“MetadataFeature”,
“NativeTypesFeature”,
“HttpCacheFeature”,
“RequestInfoFeature”,
“SessionFeature”,
“AuthFeature”,
“SessionFeature”,
“SwaggerFeature”,
“CorsFeature”
],
“StartUpErrors”:[

],
“AsyncErrors”:[

],
“Stats”:{
“RawHttpHandlers”:“6”,
“PreRequestFilters”:“0”,
“RequestBinders”:“0”,
“GlobalRequestFilters”:“2”,
“GlobalResponseFilters”:“2”,
“CatchAllHandlers”:“5”,
“Plugins”:“13”,
“ViewEngines”:“1”,
“RequestTypes”:“91”,
“ResponseTypes”:“48”,
“ServiceTypes”:“16”,
“RestPaths”:“96”,
“ContentTypes”:“5”,
“EnableFeatures”:“All”,
“VirtualPathProvider”:"[FileSystemVirtualPathProvider: C:\SomeService\bin\Debug], [ResourceVirtualPathProvider: SomeService.Host], [ResourceVirtualPathProvider: ServiceStack], [ResourceVirtualPathProvider: ServiceStack.Api.Swagger]"
},
“VirtualPathProviderFiles”:[

]
}

I’m assuming something external in the environment, maybe file permission problems?

Does your file get listed when you add a virtualPathCount? e.g:

?debug=requestinfo&virtualPathCount=100

Also are you able to download the filter through a service? e.g:

[Route("/files/{Path*}")]
public class DownloadFile 
{
    public string Path { get; set; ]
}

public object Any(DownloadFile request)
{
    var file = VirtualFileSources.GetFile(request.Path); 
    return new HttpResult(file);
}

then call with:

/files/app/index.api.js

When I add VirtualPathCount=1000 then the files are listed.