Sha256: e135e0238fe24718db7c87738d134d9fda008da24afe8128673bf34a48feae08

Contents?: true

Size: 1.09 KB

Versions: 39

Compression:

Stored size: 1.09 KB

Contents

class Webpacker::DevServer
  DEFAULT_ENV_PREFIX = "WEBPACKER_DEV_SERVER".freeze

  # Configure dev server connection timeout (in seconds), default: 0.01
  # Webpacker.dev_server.connect_timeout = 1
  cattr_accessor(:connect_timeout) { 0.01 }

  attr_reader :config

  def initialize(config)
    @config = config
  end

  def running?
    if config.dev_server.present?
      Socket.tcp(host, port, connect_timeout: connect_timeout).close
      true
    else
      false
    end
  rescue
    false
  end

  def host
    fetch(:host)
  end

  def port
    fetch(:port)
  end

  def https?
    case fetch(:https)
    when true, "true", Hash
      true
    else
      false
    end
  end

  def protocol
    https? ? "https" : "http"
  end

  def host_with_port
    "#{host}:#{port}"
  end

  def pretty?
    fetch(:pretty)
  end

  def env_prefix
    config.dev_server.fetch(:env_prefix, DEFAULT_ENV_PREFIX)
  end

  private
    def fetch(key)
      ENV["#{env_prefix}_#{key.upcase}"] || config.dev_server.fetch(key, defaults[key])
    end

    def defaults
      config.send(:defaults)[:dev_server] || {}
    end
end

Version data entries

39 entries across 39 versions & 3 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/webpacker-5.4.4/lib/webpacker/dev_server.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/webpacker-5.4.4/lib/webpacker/dev_server.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/webpacker-5.4.4/lib/webpacker/dev_server.rb
jetpacker-0.7.0 lib/webpacker/dev_server.rb
webpacker-5.4.4 lib/webpacker/dev_server.rb
jetpacker-0.6.0 lib/webpacker/dev_server.rb
webpacker-5.4.3 lib/webpacker/dev_server.rb
webpacker-5.4.2 lib/webpacker/dev_server.rb
webpacker-5.4.1 lib/webpacker/dev_server.rb
webpacker-5.4.0 lib/webpacker/dev_server.rb
webpacker-5.3.0 lib/webpacker/dev_server.rb
webpacker-5.2.2 lib/webpacker/dev_server.rb
webpacker-6.0.0.beta.7 lib/webpacker/dev_server.rb
webpacker-6.0.0.beta.6 lib/webpacker/dev_server.rb
webpacker-6.0.0.beta.5 lib/webpacker/dev_server.rb
webpacker-6.0.0.beta.4 lib/webpacker/dev_server.rb
webpacker-6.0.0.beta.3 lib/webpacker/dev_server.rb
jetpacker-0.5.0 lib/webpacker/dev_server.rb
webpacker-6.0.0.beta.2 lib/webpacker/dev_server.rb
webpacker-6.0.0.beta.1 lib/webpacker/dev_server.rb