mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-14 18:01:42 +00:00
autoconfigurar airbrake
This commit is contained in:
parent
143e392ab5
commit
9e4e2f4d6a
7 changed files with 34 additions and 21 deletions
|
@ -10,7 +10,7 @@ module Api
|
||||||
# solo si la API key es verificable. Del otro lado siempre
|
# solo si la API key es verificable. Del otro lado siempre
|
||||||
# respondemos con lo mismo.
|
# respondemos con lo mismo.
|
||||||
def create
|
def create
|
||||||
if verify_api_key
|
if site&.airbrake_valid? airbrake_token
|
||||||
BacktraceJob.perform_later site_id: params[:site_id],
|
BacktraceJob.perform_later site_id: params[:site_id],
|
||||||
params: airbrake_params.to_h
|
params: airbrake_params.to_h
|
||||||
end
|
end
|
||||||
|
@ -31,12 +31,6 @@ module Api
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
end
|
end
|
||||||
|
|
||||||
def verify_api_key
|
|
||||||
site&.verifier&.verify(airbrake_token, purpose: :airbrake) === Site::Api::AIRBRAKE_SECRET
|
|
||||||
rescue ActiveSupport::MessageVerifier::InvalidSignature
|
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
def airbrake_token
|
def airbrake_token
|
||||||
@airbrake_token ||= params[:key]
|
@airbrake_token ||= params[:key]
|
||||||
end
|
end
|
||||||
|
|
10
app/controllers/env_controller.rb
Normal file
10
app/controllers/env_controller.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class EnvController < ActionController::Base
|
||||||
|
skip_before_action :verify_authenticity_token
|
||||||
|
|
||||||
|
def index
|
||||||
|
@site = Site.find_by_name('panel')
|
||||||
|
stale? @site
|
||||||
|
end
|
||||||
|
end
|
|
@ -18,9 +18,9 @@
|
||||||
import { Notifier } from '@airbrake/browser'
|
import { Notifier } from '@airbrake/browser'
|
||||||
|
|
||||||
window.airbrake = new Notifier({
|
window.airbrake = new Notifier({
|
||||||
projectId: process.env.AIRBRAKE_SITE_ID,
|
projectId: window.env.AIRBRAKE_SITE_ID,
|
||||||
projectKey: process.env.AIRBRAKE_API_KEY,
|
projectKey: window.env.AIRBRAKE_API_KEY,
|
||||||
host: process.env.PANEL_URL
|
host: window.env.PANEL_URL
|
||||||
})
|
})
|
||||||
|
|
||||||
import 'core-js/stable'
|
import 'core-js/stable'
|
||||||
|
|
|
@ -22,6 +22,12 @@ class Site
|
||||||
@airbrake_api_key ||= verifier.generate(airbrake_secret, purpose: :airbrake)
|
@airbrake_api_key ||= verifier.generate(airbrake_secret, purpose: :airbrake)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def airbrake_valid?(token)
|
||||||
|
ActiveSupport::SecurityUtils.secure_compare(verifier.verify(token, purpose: :airbrake), airbrake_secret)
|
||||||
|
rescue ActiveSupport::MessageVerifier::InvalidSignature
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def airbrake_secret
|
def airbrake_secret
|
||||||
|
|
7
app/views/env/index.js.haml
vendored
Normal file
7
app/views/env/index.js.haml
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
= cache @site do
|
||||||
|
:plain
|
||||||
|
window.env = {
|
||||||
|
AIRBRAKE_SITE_ID: #{@site&.id || 1},
|
||||||
|
AIRBRAKE_API_KEY: "#{@site&.airbrake_api_key}",
|
||||||
|
PANEL_URL: "#{ENV['PANEL_URL']}"
|
||||||
|
}
|
|
@ -11,18 +11,13 @@
|
||||||
|
|
||||||
%title Sutty
|
%title Sutty
|
||||||
|
|
||||||
|
%script{ type: 'text/javascript', src: '/env.js' }
|
||||||
= csrf_meta_tags
|
= csrf_meta_tags
|
||||||
= stylesheet_link_tag 'application', media: 'all',
|
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload'
|
||||||
'data-turbolinks-track': 'reload'
|
= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload'
|
||||||
= javascript_pack_tag 'application',
|
= stylesheet_pack_tag 'application', 'data-turbolinks-track': 'reload'
|
||||||
'data-turbolinks-track': 'reload'
|
= javascript_include_tag 'application', 'data-turbolinks-track': 'reload'
|
||||||
= stylesheet_pack_tag 'application',
|
= favicon_link_tag 'sutty_cuadrada.png', rel: 'apple-touch-icon', type: 'image/png'
|
||||||
'data-turbolinks-track': 'reload'
|
|
||||||
= javascript_include_tag 'application',
|
|
||||||
'data-turbolinks-track': 'reload'
|
|
||||||
|
|
||||||
= favicon_link_tag 'sutty_cuadrada.png',
|
|
||||||
rel: 'apple-touch-icon', type: 'image/png'
|
|
||||||
|
|
||||||
%body{ class: yield(:body) }
|
%body{ class: yield(:body) }
|
||||||
.container-fluid#sutty
|
.container-fluid#sutty
|
||||||
|
|
|
@ -34,6 +34,7 @@ Rails.application.routes.draw do
|
||||||
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: %r{[^/]+} }
|
||||||
# Obtener archivos estáticos desde el directorio público
|
# Obtener archivos estáticos desde el directorio público
|
||||||
get '/sites/:site_id/static_file/(*file)', to: 'sites#static_file', as: 'site_static_file', constraints: { site_id: %r{[^/]+} }
|
get '/sites/:site_id/static_file/(*file)', to: 'sites#static_file', as: 'site_static_file', constraints: { site_id: %r{[^/]+} }
|
||||||
|
get '/env.js', to: 'env#index'
|
||||||
|
|
||||||
match '/api/v3/projects/:site_id/notices' => 'api/v1/notices#create', via: %i[post]
|
match '/api/v3/projects/:site_id/notices' => 'api/v1/notices#create', via: %i[post]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue