32

Should be an easy question, just can't find the answer.

I have an SPA (AngularJS) with web api which is self hosted with Owin. I use Nancy to serve the page, but I would like to get rid of Nancy and use Index.html as my single page.

I've seen this question here: How to route EVERYTHING other than Web API to /index.html

I can't use accepted answer as I don't have MVC and HomeController, the way suggested in the updated question doesn't work either, I get No HTTP resource was found that matches the request URI 'http://admin.localhost:33333/'. No route providing a controller name was found to match request URI 'http://admin.localhost:33333/'

Community
  • 1
  • 1
Burjua
  • 12,506
  • 27
  • 80
  • 111

1 Answers1

45

Move your Index.html to the root of your project. Then install-package Microsoft.Owin.StaticFiles in Package Manager Console and add the code below:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {

        const string rootFolder = ".";
        var fileSystem=new PhysicalFileSystem(rootFolder);
        var options = new FileServerOptions
                      {
                          EnableDefaultFiles = true,
                          FileSystem = fileSystem
                       };

        app.UseFileServer(options);

    }
}

This will serve up your Index.html by default.

You can checkout Scott Allen's blog for more reading:

http://odetocode.com/blogs/scott/archive/2014/02/10/building-a-simple-file-server-with-owin-and-katana.aspx

dave_k_smith
  • 655
  • 1
  • 7
  • 22
Okolie Solomon
  • 486
  • 7
  • 8
  • Thanks, this is very helpful. Just a suggestion: the package seems to be in plural form: Microsoft.Owin.StaticFiles – sp3ctum Mar 02 '16 at 05:54
  • 1
    Can we use this technique to host both UI ( angular app ) and the WebApi in the same port? If yes then can you share the code? Thanks – AustinTX Nov 10 '16 at 22:05