Search code examples
c#nancy

Nancy: Serving static content (e.g. index.html) from "/"?


I'm trying to make a single page web application using Nancy. Therefore, I want my root URL to serve a plain .html file, without any view logic or whatsoever.

I tried

Get["/"] = parameters => Response.AsHtml("content/index.html")

But there's no AsHtml.

I tried a custom bootstrapper with

conventions.StaticContentsConventions.Add(
    StaticContentConventionBuilder.AddFile("/", @"content/index.html")
);

But apparently it thinks that "/" is not a file - Nancy gives me a directory listing on http://localhost:<port>/ instead.

What do I do? This shouldn't be this hard, right?

ps. Any way to turn that directory listing off? It feels insecure.


Solution

  • Just put it your views folder and do:

    Get["/"] = _ => View["index"];
    

    The directory listing is nothing to do with Nancy, whatever hosting you're using is displaying that.