routes.rb 6.9 KB

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