<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Ruby on GeekyHub</title>
    <link>https://www.geekyhub.in/tags/ruby/</link>
    <description>Recent content in Ruby on GeekyHub</description>
    <generator>Hugo -- 0.148.1</generator>
    <language>en</language>
    <lastBuildDate>Thu, 21 Aug 2025 17:39:22 +0530</lastBuildDate>
    <atom:link href="https://www.geekyhub.in/tags/ruby/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>How to run any local project on HTTPS without any hassle</title>
      <link>https://www.geekyhub.in/post/how-to-run-any-local-project-on-https-without-any-hassle/</link>
      <pubDate>Thu, 21 Aug 2025 16:56:19 +0530</pubDate>
      <guid>https://www.geekyhub.in/post/how-to-run-any-local-project-on-https-without-any-hassle/</guid>
      <description>A fast, simple way to run any local project on HTTPS with a custom local domain. Works on macOS and Linux.</description>
      <content:encoded><![CDATA[<p>Modern browsers expect HTTPS. Cookies with <code>Secure</code>, OAuth callbacks, Service Workers, HTTP/2, and many APIs either require or work better with HTTPS.</p>
<p>I created <code>local-https</code>, a simple tool to run any local project on HTTPS with a custom local domain.</p>
<ul>
<li>No browsers hacks</li>
<li>No changing your app’s code</li>
<li>Works on macOS and Linux</li>
</ul>
<p>GitHub: <a href="https://github.com/vikas-0/local-https">https://github.com/vikas-0/local-https</a></p>
<hr>
<h2 id="what-is-local-https">What is local-https?</h2>
<p><code>local-https</code> is a small Ruby CLI that:</p>
<ul>
<li>Generates trusted local TLS certificates with <a href="https://github.com/FiloSottile/mkcert">mkcert</a></li>
<li>Maps your domain to 127.0.0.1 in <code>/etc/hosts</code></li>
<li>Runs an HTTPS reverse proxy (WEBrick) that forwards to your local app</li>
<li>Supports multiple domains via SNI</li>
<li>Optionally redirects HTTP (port 80) to HTTPS (port 443)</li>
</ul>
<p>You get a local URL like <code>https://myapp.test</code> that points to your app on <code>localhost:3000</code>.</p>
<hr>
<h2 id="quick-start">Quick start</h2>
<p>Requirements:</p>
<ul>
<li>macOS or Linux</li>
<li>Ruby 3.0+</li>
<li><code>sudo</code> access for binding to ports 443/80 and editing <code>/etc/hosts</code></li>
</ul>
<p>Install:</p>
<p>Homebrew (Tap):</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>brew tap vikas-0/tap
</span></span><span style="display:flex;"><span>brew install vikas-0/tap/local-https
</span></span></code></pre></div><p>Manual (from source):</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>git clone https://github.com/vikas-0/local-https
</span></span><span style="display:flex;"><span>cd local-https
</span></span><span style="display:flex;"><span>./install.sh
</span></span></code></pre></div><p>Steps:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># 1) Add a mapping (domain -&gt; local port)</span>
</span></span><span style="display:flex;"><span>local-https add myapp.test <span style="color:#ae81ff">3000</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 2) Start the proxy (binds to :443 and :80 for redirect)</span>
</span></span><span style="display:flex;"><span>sudo local-https start
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 3) Open your app</span>
</span></span><span style="display:flex;"><span>open https://myapp.test
</span></span></code></pre></div><p>Tips:</p>
<ul>
<li>Run in foreground for logs: <code>sudo local-https start --no-daemon</code></li>
<li>Disable HTTP→HTTPS redirect: <code>sudo local-https start --no-redirect-http</code></li>
</ul>
<hr>
<h2 id="works-with-any-tech-stack">Works with any tech stack</h2>
<p>As <code>local-https</code> simply terminates TLS and proxies to your local port. It doesn&rsquo;t require any stack specific configuration.</p>
<ul>
<li>Frontend frameworks (Next.js, React, Vue, Vite, Angular)</li>
<li>Backend APIs (Rails, Django, Flask, Express, Spring)</li>
<li>Webhooks and OAuth callback testing (GitHub, Google, etc.)</li>
</ul>
<hr>
<h2 id="how-it-works-under-the-hood">How it works (under the hood)</h2>
<ul>
<li>Certs are created with mkcert and saved in <code>~/.local-https/certs</code></li>
<li><code>/etc/hosts</code> gets <code>127.0.0.1 myapp.test # local-https</code></li>
<li>The proxy presents the correct certificate per domain (SNI) and forwards traffic to <code>http://127.0.0.1:&lt;port&gt;</code></li>
<li>Config is a simple JSON file at <code>~/.local-https/config.json</code></li>
</ul>
<hr>
<h2 id="configure-your-app-to-accept-your-custom-domain">Configure your app to accept your custom domain</h2>
<p>Most frameworks will just work, but some block unknown hosts in development. Make sure your app accepts the domain you chose (like <code>myapp.test</code>).</p>
<p>Example: Rails (<code>config/environments/development.rb</code>)</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span><span style="color:#75715e"># Allow your custom domain in dev (Rails 6+ Host Authorization)</span>
</span></span><span style="display:flex;"><span>config<span style="color:#f92672">.</span>hosts <span style="color:#f92672">&lt;&lt;</span> <span style="color:#e6db74">&#34;myapp.test&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Optional: if you generate URLs in controllers/mailers, set defaults</span>
</span></span><span style="display:flex;"><span>config<span style="color:#f92672">.</span>action_controller<span style="color:#f92672">.</span>default_url_options <span style="color:#f92672">=</span> { <span style="color:#e6db74">host</span>: <span style="color:#e6db74">&#34;myapp.test&#34;</span>, <span style="color:#e6db74">protocol</span>: <span style="color:#e6db74">&#34;https&#34;</span> }
</span></span><span style="display:flex;"><span>config<span style="color:#f92672">.</span>action_mailer<span style="color:#f92672">.</span>default_url_options     <span style="color:#f92672">=</span> { <span style="color:#e6db74">host</span>: <span style="color:#e6db74">&#34;myapp.test&#34;</span>, <span style="color:#e6db74">protocol</span>: <span style="color:#e6db74">&#34;https&#34;</span> }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># You do NOT need to force SSL in Rails dev. local-https terminates TLS and</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># forwards plain HTTP to your app on localhost:PORT.</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># config.force_ssl = false</span>
</span></span></code></pre></div><p>Notes:</p>
<ul>
<li>If you use multiple local domains, add each one with <code>config.hosts &lt;&lt; &quot;api.test&quot;</code>.</li>
<li>For subdomains, you can whitelist a regex: <code>config.hosts &lt;&lt; /.*\.test/</code>.</li>
<li>Keep your app listening on its normal dev port (e.g., 3000); no TLS changes needed in the app.</li>
</ul>
<hr>
<h2 id="why-https-locally">Why HTTPS locally?</h2>
<ul>
<li>Secure cookies, SameSite=None, Service Workers</li>
<li>OAuth callbacks and cross-origin requests</li>
<li>Matching production behavior</li>
<li>Avoid mixed content warnings and browser feature limits</li>
</ul>
<hr>
<h2 id="frequently-asked-questions-faq">Frequently asked questions (FAQ)</h2>
<ul>
<li>
<p>Can I use multiple domains?</p>
<ul>
<li>Yes. Add as many as you want: <code>local-https add api.test 4000</code>, etc.</li>
</ul>
</li>
<li>
<p>Do I need to change my app code?</p>
<ul>
<li>No. Your app still listens on HTTP (localhost). The proxy handles HTTPS.</li>
</ul>
</li>
<li>
<p>Does this work with Docker?</p>
<ul>
<li>Yes. Point the mapping port to the host port where Docker publishes your service.</li>
</ul>
</li>
<li>
<p>Is this safe?</p>
<ul>
<li>Certificates and config live in your user home. The proxy only listens locally (by default bind <code>0.0.0.0</code>, changeable in code). For public exposure you’d use a proper reverse proxy.</li>
</ul>
</li>
</ul>
]]></content:encoded>
    </item>
  </channel>
</rss>
