Socket
Book a DemoInstallSign in
Socket

local-subdomain

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

local-subdomain

1.0.3
bundlerRubygems
Version published
Maintainers
1
Created
Source

local-subdomain: Subdomain support for localhost

Description

This gem helps out when your application depends on subdomain support and you don't want to modify you /etc/hosts file all the time for your development environment.

Installation

  • Add the gem to your Gemfile
gem 'local-subdomain'
  • Run bundle install
  • Include the LocalSubdomain module into your application_controller.rb (or the controllers that requires subdomain support)
class ApplicationController < ActionController::Base
  include LocalSubdomain
  ....
end

NOTE: Do not force the gem only to be included in the development group. Because of the inclusion of the module LocalSubdomain, you'll need to have the gem available in every environment. The gem itself contains guards to only perform changes when the environment is development, so no worries or check it out yourself:

  • rack/handler.rb
  • filters/local_subdomain.rb

Configuration (optional)

By default the gem uses the domain lvh.me with the port used, when running the rails server, but it is also possible to provide a custom redirect domain and port using the following ENV variables:

ENVNotesEXAMPLE
SERVER_REDIRECT_PORTThe port number to redirect to5000
SERVER_REDIRECT_DOMAINThe domain to redirect tomy.domain.tld

What it does

Basically it does two things:

  • Extends the Rack::Handler to make sure we bind to 0.0.0.0 instead of localhost
  • Adds the LocalSubdomain module which executes a before_action to redirect to http://lvh.me:<port> (or the configured redirect domain and port)

Rack::Handler

By default, this gem uses the domain http://lvh.me to handle our requests for our subdomain(s). Request to the domain lvh.me redirects all requests to 127.0.0.1. This give's us the ability to browse to http://subsub.lvh.me:3000 and be handle request.subdomain from our controllers.

Because we're going to use the external domain http://lvh.me which redirects to 127.0.0.1 we have to make our server not to bind to localhost only.

LocalSubdomain module

This module includes a before_action which will check if the request is served by http://lvh.me. If not it will redirect to the domain.

So when we browse to http://localhost:3000 it will redirect you to http://lvh.me:3000

Supported ruby servers

I've tested the gem with:

FAQs

Package last updated on 31 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.