2019-09-05 18:56:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Api
|
|
|
|
module V1
|
|
|
|
# API
|
|
|
|
class BaseController < ActionController::Base
|
|
|
|
protect_from_forgery with: :null_session
|
2019-09-06 23:40:33 +00:00
|
|
|
respond_to :json
|
2020-03-23 20:46:19 +00:00
|
|
|
|
2020-06-17 13:40:59 +00:00
|
|
|
rescue_from ActionController::RoutingError, with: :page_not_found
|
|
|
|
|
2020-03-23 20:46:19 +00:00
|
|
|
private
|
|
|
|
|
2020-05-30 19:43:25 +00:00
|
|
|
# Realiza la inversa de Site#hostname
|
|
|
|
#
|
|
|
|
# TODO: El sitio sutty.nl no aplica a ninguno de estos y le
|
|
|
|
# tuvimos que poner 'sutty.nl..sutty.nl' para pasar el test.
|
|
|
|
def site_id
|
|
|
|
@site_id ||= if params[:site_id].end_with? Site.domain
|
|
|
|
params[:site_id].sub(/\.#{Site.domain}\z/, '')
|
|
|
|
else
|
|
|
|
params[:site_id] + '.'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-23 20:46:19 +00:00
|
|
|
def origin
|
|
|
|
request.headers['Origin']
|
|
|
|
end
|
2020-06-16 22:10:54 +00:00
|
|
|
|
|
|
|
# El primer sitio es el sitio por defecto
|
|
|
|
#
|
|
|
|
# @return [Site]
|
|
|
|
def default_site
|
|
|
|
Site.first
|
|
|
|
end
|
2020-06-17 13:40:59 +00:00
|
|
|
|
|
|
|
# Muestra una página 404
|
|
|
|
def page_not_found
|
|
|
|
render 'application/page_not_found', status: :not_found
|
|
|
|
end
|
2019-09-05 18:56:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|