-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
dev_server.rb
61 lines (50 loc) · 1005 Bytes
/
dev_server.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class Webpacker::DevServer
# Configure dev server connection timeout (in seconds), default: 0.01
# Webpacker.dev_server.connect_timeout = 1
mattr_accessor(:connect_timeout) { 0.01 }
delegate :config, to: :@webpacker
def initialize(webpacker)
@webpacker = webpacker
end
def running?
Socket.tcp(host, port, connect_timeout: connect_timeout).close
true
rescue
false
end
def hot_module_replacing?
case fetch(:hmr)
when true, "true"
true
else
false
end
end
def host
fetch(:host)
end
def port
fetch(:port)
end
def https?
case fetch(:https)
when true, "true"
true
else
false
end
end
def protocol
https? ? "https" : "http"
end
def host_with_port
"#{host}:#{port}"
end
private
def fetch(key)
ENV["WEBPACKER_DEV_SERVER_#{key.upcase}"] || config.dev_server.fetch(key, defaults[key])
end
def defaults
config.send(:defaults)[:dev_server]
end
end