Sha256: 1a007514df68a0520c09286c65dea58641274f21d4869663425627e89317ae11

Contents?: true

Size: 734 Bytes

Versions: 5

Compression:

Stored size: 734 Bytes

Contents

# frozen_string_literal: true

module Metatron
  module Controllers
    # Healthcheck service
    class Ping
      RESPONSE = { status: "up" }.to_json

      def call(env)
        req = Rack::Request.new(env)

        return access_control_allow_methods if req.options?
        return [403, { Rack::CONTENT_TYPE => "application/json" }, []] unless req.get?

        Rack::Response[200, {
          "content-type" => "application/json",
          "x-frame-options" => "SAMEORIGIN",
          "x-xss-protection" => "1; mode=block"
        }, [RESPONSE]].to_a
      end

      private

      def access_control_allow_methods
        Rack::Response[200, { "access-control-allow-methods" => %w[GET] }, []].to_a
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
metatron-0.8.2 lib/metatron/controllers/ping.rb
metatron-0.8.0 lib/metatron/controllers/ping.rb
metatron-0.7.0 lib/metatron/controllers/ping.rb
metatron-0.6.1 lib/metatron/controllers/ping.rb
metatron-0.6.0 lib/metatron/controllers/ping.rb