Terminalwire can launch web pages from the command-line interface. This is useful for opening URLs in the client’s default web browser from a command-line interface. For example:
- Opening authentication pages so users can login to your app via OAuth, Single Sign-On (SSO), Okta, “Login with Google”, “Login with Apple”, or any other web-base login flow.
- Launch web pages when users run commands, like
bin/blog post open 23could openhttps://example.com/blog/23. - Display an “authorize command-line” page to users when they start using your terminal app.
Launching web browsers
The browser.launch accepts a URL as an argument and opens it in the client’s default web browser. For example, to launch the root of your Rails app when a user runs bin/my-app open you’d implement the following code:
class MainTerminal < ApplicationTerminal desc "open", "Open in browser." def open # Launch's the root URL of a Rails app from the console browser.launch root_url end end
Rails URL helpers
The terminalwire-rails integration includes all the Rails URL helpers that you’d expect in Rails views, like root_url and everything listed under bin/rails routes.
The default_url_options[:host] is set to the host of the current request the Terminalwire client uses to connect to the server. To change these settings, you may override the default_url_options method in your ApplicationTerminal:
class ApplicationTerminal < Thor include Terminalwire::Thor def default_url_options { host: 'your-custom-host.com' } end end
Security
By default, the browser resource can only launch http and https URLs. This is to prevent malicious code from opening other types of URLs, like file, that could harm the client’s workstation.