mirror of
https://github.com/mastodon/mastodon.git
synced 2026-08-06 12:23:43 -05:00
26 lines
544 B
Ruby
26 lines
544 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Vite
|
|
# Check the status of Vite's dev server
|
|
class DevServer
|
|
WAIT_TIME = 5 # seconds
|
|
attr_reader :config
|
|
|
|
def initialize(config:)
|
|
@config = config
|
|
end
|
|
|
|
# Original idea from vite_ruby gem
|
|
def running?
|
|
return @running if defined?(@running) && Time.now.to_i - @running_checked_at < WAIT_TIME
|
|
|
|
Socket.tcp(config.host, config.port).close
|
|
@running = true
|
|
rescue
|
|
@running = false
|
|
ensure
|
|
@running_checked_at = Time.now.to_i
|
|
end
|
|
end
|
|
end
|