Class: Everywhere::MobileConfigsController

Inherits:
ActionController::API
  • Object
show all
Defined in:
lib/everywhere/mobile_configs_controller.rb

Overview

Serves the mobile shells' remote path configuration in Rails apps:

GET /everywhere/ios_v1.json      -> MobileConfigsController#show

The route is appended by Everywhere::Engine, so it shows up in rails routes and the app can override it by drawing its own. Inherits ActionController::API on purpose:

* never the app's ApplicationController — its before_actions
(authentication!) would lock the shells out, and
* not ActionController::Base — its `helper :all` resolution reaches
into the host app's helpers, which aren't loadable when the gem is
required during boot. A JSON endpoint needs none of that.

everywhere.yml is re-read on every request: tab changes go live with a deploy — or a plain file save in development, where responses are explicitly uncached so the dev shell's reload polling sees them instantly.

Instance Method Summary collapse

Instance Method Details

#apple_app_site_associationObject

GET /.well-known/apple-app-site-association — the iOS universal-links association file, generated from everywhere.yml. Extension-less and application/json, per Apple. 404 when deep linking isn't configured.



40
41
42
43
44
45
# File 'lib/everywhere/mobile_configs_controller.rb', line 40

def apple_app_site_association
  json = Config.load(::Rails.root.to_s).apple_app_site_association_json
  return head(:not_found) unless json

  render json: json
end

GET /.well-known/assetlinks.json — the Android Digital Asset Links file.



48
49
50
51
52
53
# File 'lib/everywhere/mobile_configs_controller.rb', line 48

def asset_links
  json = Config.load(::Rails.root.to_s).asset_links_json
  return head(:not_found) unless json

  render json: json
end

#resetObject

GET /everywhere/reset?to=/path — the native "reset the app" page. Auth flows redirect the shell here so it rebuilds cleanly before landing on to. Never cached (it must run every time).



58
59
60
61
62
# File 'lib/everywhere/mobile_configs_controller.rb', line 58

def reset
  response.headers["cache-control"] = "no-store"
  render html: Everywhere.mobile_reset_html(params[:to]).html_safe,
         layout: false, content_type: "text/html"
end

#showObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/everywhere/mobile_configs_controller.rb', line 23

def show
  config = Config.load(::Rails.root.to_s)

  # Never cache: the response depends on the session (filter_tabs can hide
  # tabs when signed out), so a shared/public cache could serve one user's
  # tabs to another, and a client cache would serve stale tabs across
  # sign-in/out. The endpoint is a couple of milliseconds — no cache needed.
  response.headers["cache-control"] = "no-store"

  os = params[:platform_v1].delete_suffix("_v1")
  tabs = Everywhere.resolve_tabs(config.tabs_for(os), request)
  render json: config.path_configuration_hash(os, tabs: tabs)
end