title: Force Swagger UI To Load https path when hosted on Heroku
body: <p>I have a rails 4 app with a Grape API and Swagger through the gem grape-swagger and grape-swagger-ui gems. </p>
  
  <p>In dev everything works well, I load <a href="http://localhost:3000/api/swagger" rel="nofollow">http://localhost:3000/api/swagger</a> and the swagger header's text input along the top loads the expected url, <a href="http://localhost:3000/api/swagger_doc" rel="nofollow">http://localhost:3000/api/swagger_doc</a>. This points properly to the file it seeks, swagger_doc.json.</p>
  
  <p>I've pushed this app to heroku, which forces https connections. Unfortunately, when loading <a href="https://my-app.herokuapp.com/api/swagger" rel="nofollow">https://my-app.herokuapp.com/api/swagger</a> the swagger header's text input along the top loads <a href="http://my-app.herokuapp.com/api/swagger_doc" rel="nofollow">http://my-app.herokuapp.com/api/swagger_doc</a> instead of loading <a href="https://my-app.herokuapp.com/api/swagger_doc" rel="nofollow">https://my-app.herokuapp.com/api/swagger_doc</a> (http vs https). </p>
  
  <p>I've tried coming at this from the heroku side with things like:</p>
  
  <p>routes.rb</p>
  
  <pre><code>  unless Rails.env.development? 
      get "*path" =&gt; redirect("https://my-app.herokuapp.com%{path}"), :constraints =&gt; { :protocol =&gt; "http://" } 
      post "*path" =&gt; redirect("https://my-app.herokuapp.com%{path}"), :constraints =&gt; { :protocol =&gt; "http://" } 
    end
  </code></pre>
  
  <p>config/environments/production</p>
  
  <pre><code>config.force_ssl = false
  </code></pre>
  
  <p>config/environments/production</p>
  
  <pre><code>#config.force_ssl = false
  </code></pre>
  
  <p>And I've come at it with trying to set or manipulate the base_path attribute of add_swagger_documentation.</p>
  
  <p>app/controllers/api/base.rb</p>
  
  <pre><code>base_path: "my-app.herokuapp.com",
  </code></pre>
  
  <p>app/controllers/api/base.rb</p>
  
  <pre><code>base_path: "http://my-app.herokuapp.com",
  </code></pre>
  
  <p>app/controllers/api/base.rb</p>
  
  <pre><code>base_path: = lambda do |request|
                 return "http://my-app.herokuapp.com"
               end
  </code></pre>
  
  <p>app/controllers/api/base.rb</p>
  
  <pre><code>base_path: lambda { |request| "http://#{request.host}:#{request.port}" }
  </code></pre>
  
  <p>I recently clicked "view raw" on one of my resources and noticed that it was picking up my changes to base_path but that base_path isn't even used to populate the url in the text input in the swagger header. It seems to be generated from a js file. I'm unable to edit it and would happily accept a hack to do so as a solution. Here's that raw output:</p>
  
  <p><a href="https://gist.github.com/johnnygoodman/5fd246765dc5236fb8c4" rel="nofollow">https://gist.github.com/johnnygoodman/5fd246765dc5236fb8c4</a></p>
  
  <p>The line of interest is:</p>
  
  <pre><code>"basePath":"http://localhost:3000/my-app.herokuapp.com"
  </code></pre>
  
  <p>Which would break the app if it was being populated and used, but it is not. I don't see an option in the grape-swagger gem that I can use to pass in this variable and change the path to https.</p>
  
  <p>In conclusion: </p>
  
  <p>I'd like the swagger text input box to load <a href="https://my-app.herokuapp.com/api/swagger_doc" rel="nofollow">https://my-app.herokuapp.com/api/swagger_doc</a> when I visit <a href="https://my-app.herokuapp.com/api/swagger" rel="nofollow">https://my-app.herokuapp.com/api/swagger</a>. </p>
  
  <p>Anyone know a hack to accomplish this on heroku?  </p>