routes.rb 6.9 KB

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