routes.rb 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. # frozen_string_literal: true
  2. require 'sidekiq_unique_jobs/web'
  3. require 'sidekiq-scheduler/web'
  4. class RedirectWithVary < ActionDispatch::Routing::PathRedirect
  5. def build_response(req)
  6. super.tap do |response|
  7. response.headers['Vary'] = 'Origin, Accept'
  8. end
  9. end
  10. end
  11. def redirect_with_vary(path)
  12. RedirectWithVary.new(301, path)
  13. end
  14. Rails.application.routes.draw do
  15. # Paths of routes on the web app that to not require to be indexed or
  16. # have alternative format representations requiring separate controllers
  17. web_app_paths = %w(
  18. /getting-started
  19. /keyboard-shortcuts
  20. /home
  21. /public
  22. /public/local
  23. /public/remote
  24. /conversations
  25. /lists/(*any)
  26. /notifications
  27. /favourites
  28. /bookmarks
  29. /pinned
  30. /start/(*any)
  31. /directory
  32. /explore/(*any)
  33. /search
  34. /publish
  35. /follow_requests
  36. /blocks
  37. /domain_blocks
  38. /mutes
  39. /followed_tags
  40. /statuses/(*any)
  41. /deck/(*any)
  42. ).freeze
  43. root 'home#index'
  44. mount LetterOpenerWeb::Engine, at: 'letter_opener' if Rails.env.development?
  45. get 'health', to: 'health#show'
  46. authenticate :user, lambda { |u| u.role&.can?(:view_devops) } do
  47. mount Sidekiq::Web, at: 'sidekiq', as: :sidekiq
  48. mount PgHero::Engine, at: 'pghero', as: :pghero
  49. end
  50. use_doorkeeper do
  51. controllers authorizations: 'oauth/authorizations',
  52. authorized_applications: 'oauth/authorized_applications',
  53. tokens: 'oauth/tokens'
  54. end
  55. get '.well-known/host-meta', to: 'well_known/host_meta#show', as: :host_meta, defaults: { format: 'xml' }
  56. get '.well-known/nodeinfo', to: 'well_known/node_info#index', as: :nodeinfo, defaults: { format: 'json' }
  57. get '.well-known/webfinger', to: 'well_known/webfinger#show', as: :webfinger
  58. get '.well-known/change-password', to: redirect('/auth/edit')
  59. get '.well-known/proxy', to: redirect { |_, request| "/authorize_interaction?#{request.params.to_query}" }
  60. get '/nodeinfo/2.0', to: 'well_known/node_info#show', as: :nodeinfo_schema
  61. get 'manifest', to: 'manifests#show', defaults: { format: 'json' }
  62. get 'intent', to: 'intents#show'
  63. get 'custom.css', to: 'custom_css#show', as: :custom_css
  64. get 'remote_interaction_helper', to: 'remote_interaction_helper#index'
  65. resource :instance_actor, path: 'actor', only: [:show] do
  66. resource :inbox, only: [:create], module: :activitypub
  67. resource :outbox, only: [:show], module: :activitypub
  68. end
  69. get '/invite/:invite_code', constraints: ->(req) { req.format == :json }, to: 'api/v1/invites#show'
  70. devise_scope :user do
  71. get '/invite/:invite_code', to: 'auth/registrations#new', as: :public_invite
  72. resource :unsubscribe, only: [:show, :create], controller: :mail_subscriptions
  73. namespace :auth do
  74. resource :setup, only: [:show, :update], controller: :setup
  75. resource :challenge, only: [:create], controller: :challenges
  76. get 'sessions/security_key_options', to: 'sessions#webauthn_options'
  77. post 'captcha_confirmation', to: 'confirmations#confirm_captcha', as: :captcha_confirmation
  78. end
  79. end
  80. devise_for :users, path: 'auth', format: false, controllers: {
  81. omniauth_callbacks: 'auth/omniauth_callbacks',
  82. sessions: 'auth/sessions',
  83. registrations: 'auth/registrations',
  84. passwords: 'auth/passwords',
  85. confirmations: 'auth/confirmations',
  86. }
  87. # rubocop:disable Style/FormatStringToken - those do not go through the usual formatting functions and are not safe to correct
  88. get '/users/:username', to: redirect_with_vary('/@%{username}'), constraints: lambda { |req| req.format.nil? || req.format.html? }
  89. get '/users/:username/following', to: redirect_with_vary('/@%{username}/following'), constraints: lambda { |req| req.format.nil? || req.format.html? }
  90. get '/users/:username/followers', to: redirect_with_vary('/@%{username}/followers'), constraints: lambda { |req| req.format.nil? || req.format.html? }
  91. get '/users/:username/statuses/:id', to: redirect_with_vary('/@%{username}/%{id}'), constraints: lambda { |req| req.format.nil? || req.format.html? }
  92. # rubocop:enable Style/FormatStringToken
  93. get '/authorize_follow', to: redirect { |_, request| "/authorize_interaction?#{request.params.to_query}" }
  94. resources :accounts, path: 'users', only: [:show], param: :username do
  95. resources :statuses, only: [:show] do
  96. member do
  97. get :activity
  98. get :embed
  99. end
  100. resources :replies, only: [:index], module: :activitypub
  101. end
  102. resources :followers, only: [:index], controller: :follower_accounts
  103. resources :following, only: [:index], controller: :following_accounts
  104. resource :outbox, only: [:show], module: :activitypub
  105. resource :inbox, only: [:create], module: :activitypub
  106. resource :claim, only: [:create], module: :activitypub
  107. resources :collections, only: [:show], module: :activitypub
  108. resource :followers_synchronization, only: [:show], module: :activitypub
  109. end
  110. resource :inbox, only: [:create], module: :activitypub
  111. get '/:encoded_at(*path)', to: redirect("/@%{path}"), constraints: { encoded_at: /%40/ }
  112. constraints(username: %r{[^@/.]+}) do
  113. get '/@:username', to: 'accounts#show', as: :short_account
  114. get '/@:username/with_replies', to: 'accounts#show', as: :short_account_with_replies
  115. get '/@:username/media', to: 'accounts#show', as: :short_account_media
  116. get '/@:username/tagged/:tag', to: 'accounts#show', as: :short_account_tag
  117. end
  118. constraints(account_username: %r{[^@/.]+}) do
  119. get '/@:account_username/following', to: 'following_accounts#index'
  120. get '/@:account_username/followers', to: 'follower_accounts#index'
  121. get '/@:account_username/:id', to: 'statuses#show', as: :short_account_status
  122. get '/@:account_username/:id/embed', to: 'statuses#embed', as: :embed_short_account_status
  123. end
  124. get '/@:username_with_domain/(*any)', to: 'home#index', constraints: { username_with_domain: %r{([^/])+?} }, as: :account_with_domain, format: false
  125. get '/settings', to: redirect('/settings/profile')
  126. draw(:settings)
  127. namespace :disputes do
  128. resources :strikes, only: [:show, :index] do
  129. resource :appeal, only: [:create]
  130. end
  131. end
  132. resources :media, only: [:show] do
  133. get :player
  134. end
  135. resources :tags, only: [:show]
  136. resources :emojis, only: [:show]
  137. resources :invites, only: [:index, :create, :destroy]
  138. resources :filters, except: [:show] do
  139. resources :statuses, only: [:index], controller: 'filters/statuses' do
  140. collection do
  141. post :batch
  142. end
  143. end
  144. end
  145. resource :relationships, only: [:show, :update]
  146. resource :statuses_cleanup, controller: :statuses_cleanup, only: [:show, :update]
  147. get '/media_proxy/:id/(*any)', to: 'media_proxy#show', as: :media_proxy, format: false
  148. get '/backups/:id/download', to: 'backups#download', as: :download_backup, format: false
  149. resource :authorize_interaction, only: [:show]
  150. resource :share, only: [:show]
  151. draw(:admin)
  152. get '/admin', to: redirect('/admin/dashboard', status: 302)
  153. draw(:api)
  154. web_app_paths.each do |path|
  155. get path, to: 'home#index'
  156. end
  157. get '/web/(*any)', to: redirect('/%{any}', status: 302), as: :web, defaults: { any: '' }, format: false
  158. get '/about', to: 'about#show'
  159. get '/about/more', to: redirect('/about')
  160. get '/privacy-policy', to: 'privacy#show', as: :privacy_policy
  161. get '/terms', to: redirect('/privacy-policy')
  162. match '/', via: [:post, :put, :patch, :delete], to: 'application#raise_not_found', format: false
  163. match '*unmatched_route', via: :all, to: 'application#raise_not_found', format: false
  164. end