Skip to content

Commit 62cbae4

Browse files
authored
Merge pull request #87 from Shopify/andyw8/ensure-app-uri-file-cleaned-up
Ensure `app_uri.txt` is cleaned up when Rails server shuts down
2 parents 8bac78e + 601cf66 commit 62cbae4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/ruby_lsp_rails/railtie.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ class Railtie < ::Rails::Railtie
1414
if defined?(::Rails::Server)
1515
ssl_enable, host, port = ::Rails::Server::Options.new.parse!(ARGV).values_at(:SSLEnable, :Host, :Port)
1616
app_uri = "#{ssl_enable ? "https" : "http"}://#{host}:#{port}"
17-
File.write("#{::Rails.root}/tmp/app_uri.txt", app_uri)
17+
app_uri_path = "#{::Rails.root}/tmp/app_uri.txt"
18+
File.write(app_uri_path, app_uri)
19+
20+
at_exit do
21+
# The app_uri.txt file should only exist when the server is running. The extension uses its presence to
22+
# report if the server is running or not. If the server is not running, some of the extension features
23+
# will not be available.
24+
File.delete(app_uri_path) if File.exist?(app_uri_path)
25+
end
1826
end
1927
end
2028
end

0 commit comments

Comments
 (0)