routes.rb 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. # frozen_string_literal: true
  2. require 'sidekiq_unique_jobs/web' if ENV['ENABLE_SIDEKIQ_UNIQUE_JOBS_UI'] == true
  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. /links/(*any)
  27. /notifications/(*any)
  28. /notifications_v2/(*any)
  29. /favourites
  30. /bookmarks
  31. /pinned
  32. /start/(*any)
  33. /directory
  34. /explore/(*any)
  35. /search
  36. /publish
  37. /follow_requests
  38. /blocks
  39. /domain_blocks
  40. /mutes
  41. /followed_tags
  42. /statuses/(*any)
  43. /deck/(*any)
  44. ).freeze
  45. root 'home#index'
  46. mount LetterOpenerWeb::Engine, at: 'letter_opener' if Rails.env.development?
  47. get 'health', to: 'health#show'
  48. authenticate :user, ->(user) { user.role&.can?(:view_devops) } do
  49. mount Sidekiq::Web, at: 'sidekiq', as: :sidekiq
  50. mount PgHero::Engine, at: 'pghero', as: :pghero
  51. end
  52. use_doorkeeper do
  53. controllers authorizations: 'oauth/authorizations',
  54. authorized_applications: 'oauth/authorized_applications',
  55. tokens: 'oauth/tokens'
  56. end
  57. namespace :oauth do
  58. # As this is borrowed from OpenID, the specification says we must also support
  59. # POST for the userinfo endpoint:
  60. # https://openid.net/specs/openid-connect-core-1_0.html#UserInfo
  61. match 'userinfo', via: [:get, :post], to: 'userinfo#show', defaults: { format: 'json' }
  62. end
  63. scope path: '.well-known' do
  64. scope module: :well_known do
  65. get 'oauth-authorization-server', to: 'oauth_metadata#show', as: :oauth_metadata, defaults: { format: 'json' }
  66. get 'host-meta', to: 'host_meta#show', as: :host_meta
  67. get 'nodeinfo', to: 'node_info#index', as: :nodeinfo, defaults: { format: 'json' }
  68. get 'webfinger', to: 'webfinger#show', as: :webfinger
  69. end
  70. get 'change-password', to: redirect('/auth/edit'), as: nil
  71. get 'proxy', to: redirect { |_, request| "/authorize_interaction?#{request.params.to_query}" }, as: nil
  72. end
  73. get '/nodeinfo/2.0', to: 'well_known/node_info#show', as: :nodeinfo_schema
  74. get 'manifest', to: 'manifests#show', defaults: { format: 'json' }
  75. get 'intent', to: 'intents#show'
  76. get 'custom.css', to: 'custom_css#show', as: :custom_css
  77. get 'remote_interaction_helper', to: 'remote_interaction_helper#index'
  78. resource :instance_actor, path: 'actor', only: [:show] do
  79. scope module: :activitypub do
  80. resource :inbox, only: [:create]
  81. resource :outbox, only: [:show]
  82. end
  83. end
  84. get '/invite/:invite_code', constraints: ->(req) { req.format == :json }, to: 'api/v1/invites#show'
  85. devise_scope :user do
  86. get '/invite/:invite_code', to: 'auth/registrations#new', as: :public_invite
  87. resource :unsubscribe, only: [:show, :create], controller: :mail_subscriptions
  88. namespace :auth do
  89. resource :setup, only: [:show, :update], controller: :setup
  90. resource :challenge, only: [:create]
  91. get 'sessions/security_key_options', to: 'sessions#webauthn_options'
  92. post 'captcha_confirmation', to: 'confirmations#confirm_captcha', as: :captcha_confirmation
  93. end
  94. end
  95. scope module: :auth do
  96. devise_for :users, path: 'auth', format: false
  97. end
  98. with_options constraints: ->(req) { req.format.nil? || req.format.html? } do
  99. get '/users/:username', to: redirect_with_vary('/@%{username}')
  100. get '/users/:username/following', to: redirect_with_vary('/@%{username}/following')
  101. get '/users/:username/followers', to: redirect_with_vary('/@%{username}/followers')
  102. get '/users/:username/statuses/:id', to: redirect_with_vary('/@%{username}/%{id}')
  103. end
  104. get '/authorize_follow', to: redirect { |_, request| "/authorize_interaction?#{request.params.to_query}" }
  105. resources :accounts, path: 'users', only: [:show], param: :username do
  106. resources :statuses, only: [:show] do
  107. member do
  108. get :activity
  109. get :embed
  110. end
  111. resources :replies, only: [:index], module: :activitypub
  112. resources :likes, only: [:index], module: :activitypub
  113. resources :shares, only: [:index], module: :activitypub
  114. end
  115. resources :followers, only: [:index], controller: :follower_accounts
  116. resources :following, only: [:index], controller: :following_accounts
  117. scope module: :activitypub do
  118. resource :outbox, only: [:show]
  119. resource :inbox, only: [:create]
  120. resources :collections, only: [:show]
  121. resource :followers_synchronization, only: [:show]
  122. end
  123. end
  124. resource :inbox, only: [:create], module: :activitypub
  125. constraints(encoded_path: /%40.*/) do
  126. get '/:encoded_path', to: redirect { |params|
  127. "/#{params[:encoded_path].gsub('%40', '@')}"
  128. }
  129. end
  130. constraints(username: %r{[^@/.]+}) do
  131. with_options to: 'accounts#show' do
  132. get '/@:username', as: :short_account
  133. get '/@:username/with_replies', as: :short_account_with_replies
  134. get '/@:username/media', as: :short_account_media
  135. get '/@:username/tagged/:tag', as: :short_account_tag
  136. end
  137. end
  138. constraints(account_username: %r{[^@/.]+}) do
  139. get '/@:account_username/following', to: 'following_accounts#index'
  140. get '/@:account_username/followers', to: 'follower_accounts#index'
  141. get '/@:account_username/:id', to: 'statuses#show', as: :short_account_status
  142. get '/@:account_username/:id/embed', to: 'statuses#embed', as: :embed_short_account_status
  143. end
  144. get '/@:username_with_domain/(*any)', to: 'home#index', constraints: { username_with_domain: %r{([^/])+?} }, as: :account_with_domain, format: false
  145. get '/settings', to: redirect('/settings/profile')
  146. draw(:settings)
  147. namespace :disputes do
  148. resources :strikes, only: [:show, :index] do
  149. resource :appeal, only: [:create]
  150. end
  151. end
  152. namespace :redirect do
  153. resources :accounts, only: :show
  154. resources :statuses, only: :show
  155. end
  156. resources :media, only: [:show] do
  157. get :player
  158. end
  159. resources :tags, only: [:show]
  160. resources :emojis, only: [:show]
  161. resources :invites, only: [:index, :create, :destroy]
  162. resources :filters, except: [:show] do
  163. resources :statuses, only: [:index], controller: 'filters/statuses' do
  164. collection do
  165. post :batch
  166. end
  167. end
  168. end
  169. resource :relationships, only: [:show, :update]
  170. resources :severed_relationships, only: [:index] do
  171. member do
  172. constraints(format: :csv) do
  173. get :followers
  174. get :following
  175. end
  176. end
  177. end
  178. resource :statuses_cleanup, controller: :statuses_cleanup, only: [:show, :update]
  179. get '/media_proxy/:id/(*any)', to: 'media_proxy#show', as: :media_proxy, format: false
  180. get '/backups/:id/download', to: 'backups#download', as: :download_backup, format: false
  181. resource :authorize_interaction, only: [:show]
  182. resource :share, only: [:show]
  183. draw(:admin)
  184. get '/admin', to: redirect('/admin/dashboard', status: 302)
  185. draw(:api)
  186. web_app_paths.each do |path|
  187. get path, to: 'home#index'
  188. end
  189. get '/web/(*any)', to: redirect('/%{any}', status: 302), as: :web, defaults: { any: '' }, format: false
  190. get '/about', to: 'about#show'
  191. get '/about/more', to: redirect('/about')
  192. get '/privacy-policy', to: 'privacy#show', as: :privacy_policy
  193. get '/terms', to: redirect('/privacy-policy')
  194. match '/', via: [:post, :put, :patch, :delete], to: 'application#raise_not_found', format: false
  195. match '*unmatched_route', via: :all, to: 'application#raise_not_found', format: false
  196. end