Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OWIN send static file for multiple routes

I'm making a SPA which sits on top of ASP.Net WebAPI. I'm waiting to use HTML5 history rather than #/ for history routing but that poses a problem for deep linking, I need to make sure / and /foo/bar all return the same HTML file (and my JS will render the right part of the SPA).

How do I get OWIN/Katana to return the same HTML file for multiple different urls?

like image 781
Aaron Powell Avatar asked Dec 01 '14 05:12

Aaron Powell


1 Answers

To make things simple, while still keeping all the caching goodness etc. from the StaticFiles middleware, I'd just rewrite the request path using an inline middleware, like this

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.Map("/app", spa =>
        {
            spa.Use((context, next) =>
            {
                context.Request.Path = new PathString("/index.html");

                return next();
            });

            spa.UseStaticFiles();
        });

        app.UseWelcomePage();
    }
}

This will serve the welcome page on anything but /app/*, which will always serve index.html instead.

like image 70
khellang Avatar answered Oct 19 '22 07:10

khellang