routes.rb 7.4 KB

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