title: How to get Swagger Plugin working within self hosted servicestack
body: <p>I've re-asked this question with examples provided on github and a drop box download link for anyone that want to run the code themselves : <a href="https://stackoverflow.com/questions/19377691/swagger-not-working-on-a-self-hosted-servicestack-service">Swagger not working on a self hosted ServiceStack Service</a></p>
  
  <hr>
  
  <p>I had my servicestack JSON service running inside my website solution, under the '/api/ path, but now I'd like to split out that service stack portion and have it running as a self hosted windows service. My problem is, myself and the other developers find the Swagger plugin very useful for testing purposes, but now that it's self hosted it appears the HTTPHandler is setup only for only handling the service routes, and plain HTML does not work.</p>
  
  <p>How do I fix this?</p>
  
  <p>URL : <code>http://localhost:8081/Swagger-UI/Index.html</code></p>
  
  <p>Response : </p>
  
  <pre><code>Handler for Request not found: 
  
  Request.HttpMethod: GET
  Request.HttpMethod: GET
  Request.PathInfo: /Swagger-UI/Index.html
  Request.QueryString: 
  Request.RawUrl: /Swagger-UI/Index.html
  </code></pre>
  
  <p>Nuget packages installed :</p>
  
  <pre><code>ServiceStack
  ServiceStack.Razor
  </code></pre>
  
  <p>Update for @marfarma</p>
  
  <p>My app.config file has nothing ServiceStack related inside it...</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;startup&gt;
      &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
    &lt;/startup&gt;
    &lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;binding name="BasicHttpBinding_service1_V2_SSL" /&gt;
          &lt;binding name="BasicHttpBinding_service2_V1_SSL" /&gt;
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;client&gt;
        &lt;!-- bespoke services I'm connecting too --&gt;
      &lt;/client&gt;
    &lt;/system.serviceModel&gt;
    &lt;appSettings&gt;
       &lt;!-- bespoke app settings --&gt;
    &lt;/appSettings&gt;  
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Program.cs : </p>
  
  <pre><code>           AppHostHttpListenerBase appHost = new my.HttpApi.myApiServiceHostBase("My Service", "my.ApiService");   
  
  
             string listeningURL = "http://localhost:8081/";
  
              var appSettings = new ServiceStack.Configuration.AppSettings();
              my.HttpApi.FakeProvider.ProductProvider.Init(appSettings);
              my.HttpApi.FakeProvider.UserProvider.Init(appSettings);
  
  #if DEBUG
  
              try
              {
                  appHost.Init();
                  appHost.Start(listeningURL);
  
                  Console.WriteLine("Press &lt;CTRL&gt;+C to stop.");
                  Thread.Sleep(Timeout.Infinite);
              }
              catch (Exception ex)
              {
                  Console.WriteLine("ERROR: {0}: {1}", ex.GetType().Name, ex.Message);
                  throw;
              }
              finally
              {
                  appHost.Stop();
              }
  
              Console.WriteLine("WinServiceAppHost has finished");
  </code></pre>
  
  <p>configure method :</p>
  
  <pre><code>public override void Configure(Funq.Container container)
          {
              Plugins.RemoveAll(x =&gt; x is CsvFormat);
              Plugins.RemoveAll(x =&gt; x is HtmlFormat);
  
              ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;
  
              //register any dependencies your services use, e.g:
              //container.Register&lt;ICacheClient&gt;(new MemoryCacheClient());
  
              var config = new EndpointHostConfig { DefaultContentType = ContentType.Json, ServiceStackHandlerFactoryPath = "api" };
  
  
              SetConfig(config);
              Plugins.Add(new ServiceStack.Api.Swagger.SwaggerFeature());
  
              Dictionary&lt;Type, string[]&gt; serviceRoutes = new Dictionary&lt;Type, string[]&gt;();
              serviceRoutes.Add(typeof(AuthService), new[] { "/auth/user" });
  
  
              AuthFeature authFeature = new AuthFeature(() =&gt; new AuthUserSession(), new IAuthProvider[] { new FakeCredentialsAuthProvider() });
              authFeature.IncludeAssignRoleServices = false;
              authFeature.ServiceRoutes = serviceRoutes;                      //specify manual auth routes        
  
              Plugins.Add(authFeature);
  
              container.Register&lt;ICacheClient&gt;(new MemoryCacheClient());
              var userRep = new InMemoryAuthRepository();
              container.Register&lt;IUserAuthRepository&gt;(userRep);
  
              Plugins.Add(new CorsFeature(allowedOrigins: "*",
                          allowedMethods: "GET, POST, OPTIONS",
                          //allowedHeaders: "Content-Type",
                          allowedHeaders : "Origin, X-Atmosphere-tracking-id, X-Atmosphere-Framework, X-Cache-Date, Content-Type, X-Atmosphere-Transport,  *",
                          allowCredentials: false));
  }
  </code></pre>
  
  <p>Update 2 :</p>
  
  <p>1.) Removed the plugins sections above that is removing html and csv</p>
  
  <p>2.) Ran the following in the package manager (nuget) : </p>
  
  <pre><code>Install-Package ServiceStack.Api.Swagger
  </code></pre>
  
  <p>still no handler found.</p>
  
  <p>The advice in this question ( <a href="https://stackoverflow.com/q/16649066/149060">ServiceStack: No /swagger-ui/index.html</a> ) that marfarma pointed me at suggests I may not have the 'swagger-ui' html and javascript present. <strong>I do</strong>. </p>
  
  <p>It appears the self hosted servicestack only 'handles' the specified routes, and when I ask the self hosted service to deliver the swagger html and javascript, I get the "handler for request not found" error above. </p>
  
  <p>When I visit the /resources address in my self hosted service, it shows the expected page and data (suggesting the swagger plugin is doing its thing properly), but when I load up the swagger html and javascript from the file system (not 'served' by my service), and provide it the resource url that works, I get "Can't read from server. It may not have the appropriate access-control-origin settings.", which appears to be a CORS issue, but I've enabled cors on my service (it appears an issue with the Swagger UI code), the swagger-ui send my self hosted service a request sent as 'OPTIONS' (instead of GET or POST), and the options request fails :(</p>