From 5392f9a942f1d876aa3e60700a3ed4fe2b0b9c82 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 19 Feb 2020 19:29:06 -0300 Subject: [PATCH] permitir dominios alternativos #122 --- app/controllers/api/v1/sites_controller.rb | 3 ++- app/models/deploy_alternative_domain.rb | 23 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 app/models/deploy_alternative_domain.rb diff --git a/app/controllers/api/v1/sites_controller.rb b/app/controllers/api/v1/sites_controller.rb index 18550feb..fcf694e0 100644 --- a/app/controllers/api/v1/sites_controller.rb +++ b/app/controllers/api/v1/sites_controller.rb @@ -8,7 +8,8 @@ module Api password: ENV['HTTP_BASIC_PASSWORD'] def index - render json: Site.all.order(:name).pluck(:name) + render json: Site.all.order(:name).pluck(:name) + + DeployAlternativeDomain.all.map(&:hostname) end # Detecta si se puede generar un certificado diff --git a/app/models/deploy_alternative_domain.rb b/app/models/deploy_alternative_domain.rb new file mode 100644 index 00000000..e4960e65 --- /dev/null +++ b/app/models/deploy_alternative_domain.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +# Soportar dominios alternativos +class DeployAlternativeDomain < Deploy + store :values, accessors: %i[hostname], coder: JSON + + # Generar un link simbólico del sitio principal al alternativo + def deploy + File.symlink?(destination) || + File.symlink(site.hostname, destination).zero? + end + + # No hay límite para los dominios alternativos + def limit; end + + def size + File.size destination + end + + def destination + File.join(Rails.root, '_deploy', hostname.gsub(/\.\z/, '')) + end +end