diff --git a/config/routes.rb b/config/routes.rb index 9d5c974a..3dfc4c85 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,10 @@ # frozen_string_literal: true +# Como el sitio puede contener puntos, no queremos confundirlos con +# tipos de contenido, por ejemplo que /sites/site.org no intente service +# text/org. +SITE_ID_RE = %r{[^/]+}.freeze + Rails.application.routes.draw do devise_for :usuaries get '/.well-known/change-password', to: redirect('/usuaries/edit') @@ -18,7 +23,7 @@ Rails.application.routes.draw do resources :remote_flags, only: %i[show] end - resources :sites, only: %i[index], constraints: { site_id: /[a-z0-9\-.]+/, id: /[a-z0-9\-.]+/ } do + resources :sites, only: %i[index], constraints: { site_id: SITE_ID_RE, id: SITE_ID_RE } do get :'invitades/cookie', to: 'invitades#cookie' post :'posts/:layout', to: 'posts#create', as: :posts @@ -42,12 +47,12 @@ Rails.application.routes.draw do # Las rutas privadas empiezan con una ruta Ășnica para poder hacer un # alias en nginx sin tener que usar expresiones regulares para # detectar el nombre del sitio. - get '/sites/private/:site_id(*file)', to: 'private#show', constraints: { site_id: %r{[^/]+} } + get '/sites/private/:site_id(*file)', to: 'private#show', constraints: { site_id: SITE_ID_RE } get '/env.js', to: 'env#index' match '/api/v3/projects/:site_id/notices' => 'api/v1/notices#create', via: %i[post] - resources :sites, constraints: { site_id: %r{[^/]+}, id: %r{[^/]+} } do + resources :sites, constraints: { site_id: SITE_ID_RE, id: SITE_ID_RE } do # Gestionar actualizaciones del sitio get 'pull', to: 'sites#fetch' post 'pull', to: 'sites#merge'