Serving multiple SPAs from wwwroot (fallback)

I’ve read about the fallback and SPA fallback here:
I have multiple SPA applications, all using the API that is built with SS.

Is it possible (or advisable) to serve this from within wwwroot, using StaticPages and Fallback (for client side routing)? I know it can be done for a single SPA living at wwwroot, but what if I’ve got another SPA in a sub folder of wwwroot? Currently using some IIS trickery, so just wondering if it could be done better with SS.

It’s whatever works best for you, if you have custom requirements I’d likely have a custom FallbackForClientRoutes impl that returns the different static index.html file depending on the request.

1 Like

Ah, I get it. In this example from the docs, I’ll inspect the PathInfo in the service and do whatever I want (such as GetPageResult("/") for some paths and GetPageResult("/folder/index.html") for others, e.g. using RegEx for the path matching.

[FallbackRoute("/{PathInfo*}", Matches="AcceptsHtml")]
public class FallbackForClientRoutes
    public string PathInfo { get; set; }

public class MyServices : Service
    //Return index.html for unmatched requests so routing is handled on client
    public object Any(FallbackForClientRoutes request) => Request.GetPageResult("/");

Yeah you’d want to inspect the request to return the right fallback page, you can use Request.GetPageResult("/") if you have SharpPagesFeature plugin configured, otherwise there’s other fallback examples:

//Return static HTML file
return new HttpResult(VirtualFileSources.GetFile("index.html"));

//Return HTML String
return new HttpResult(VirtualFileSources.GetFile("index.html").ReadAllText());

//Return ServiceStack.Razor View
return new HttpResult(request)
    View = "/default.cshtml"
1 Like