Sha256: 9b230b6dd917b31f8adcdd8a369a06735661c18a70270b23c2e711aa76fb59a2

Contents?: true

Size: 1.93 KB

Versions: 6

Compression:

Stored size: 1.93 KB

Contents

# typed: false
# frozen_string_literal: true

require "propshaft"
require "jbuilder"
require "solid_queue"
require "mission_control/jobs"

module Hephaestus
  class Engine < ::Rails::Engine
    isolate_namespace Hephaestus
    config.generators.api_only = true

    GIT_SHA = case Rails.env
    when "production", "staging"
      ENV["GIT_SHA"]
    when "development"
      %x(git rev-parse HEAD)
    when "test"
      "deadbeef"
    end.chomp

    require "hephaestus/http"

    initializer "hephaestus.add_middleware" do |app|
      Hephaestus::Engine.root.glob("lib/hephaestus/middleware/*.{rb}").each { |file| require_relative file }

      app.config.middleware.insert(0, Hephaestus::Middleware::TracingAttributes)
      app.config.middleware.insert(0, Hephaestus::Middleware::MalformedRequest)

      app.config.middleware.use(Hephaestus::Middleware::OpenapiValidation)
    end

    initializer :append_migrations do |app|
      unless app.root.to_s.match?(root.to_s)
        config.paths["db/migrate"].expanded.each do |expanded_path|
          app.config.paths["db/migrate"] << expanded_path
          ActiveRecord::Migrator.migrations_paths << expanded_path
        end
      end
    end

    class << self
      def insert_routes
        Rails.application.routes.draw do
          # Staff pages
          get("staff", to: "staff#index")

          constraints(->(request) { StaffController.staff_request?(request) }) do
            mount(MissionControl::Jobs::Engine, at: "staff/jobs", as: :staff_jobs)
          end

          #############################################
          # error pages -- these MUST be at the end! ##
          #############################################

          get("/500", to: "application#render500") if Rails.env.production? || Rails.env.staging?

          match("/", to: "application#not_found", via: :all)
          match("/*unmatched_route", to: "application#not_found", via: :all)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hephaestus-0.7.2.4 lib/hephaestus/engine.rb
hephaestus-0.7.2.3 lib/hephaestus/engine.rb
hephaestus-0.7.2.2 lib/hephaestus/engine.rb
hephaestus-0.7.2.1 lib/hephaestus/engine.rb
hephaestus-0.7.2 lib/hephaestus/engine.rb
hephaestus-0.7.1 lib/hephaestus/engine.rb