Sha256: 578387f1cae06b026496b650144592c16f413a7577cd7e3f154437a3d4706d33

Contents?: true

Size: 1.3 KB

Versions: 10

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require "graphql"
require "rack/cors"

require "decidim/core"
require "decidim/api/graphiql/config"

if ActiveSupport::Inflector.method(:inflections).arity.zero?
  # Rails 3 does not take a language in inflections.
  ActiveSupport::Inflector.inflections do |inflect|
    inflect.acronym("GraphiQL")
  end
else
  ActiveSupport::Inflector.inflections(:en) do |inflect|
    inflect.acronym("GraphiQL")
  end
end

module Decidim
  module Api
    # Mountable engine that exposes a side-wide API for Decidim.
    class Engine < ::Rails::Engine
      isolate_namespace Decidim::Api

      initializer "decidim_api.middleware" do |app|
        app.config.middleware.insert_before 0, Rack::Cors do
          allow do
            origins "*"
            resource "/api", headers: :any, methods: [:post, :options]
          end
        end
      end

      initializer "decidim_api.graphiql" do
        Decidim::GraphiQL::Rails.config.tap do |config|
          config.query_params = true
          config.initial_query = ERB::Util.html_escape(
            File.read(File.join(__dir__, "graphiql-initial-query.txt"))
          )
        end
      end

      initializer "decidim_api.webpacker.assets_path" do
        Decidim.register_assets_path File.expand_path("app/packs", root)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
decidim-api-0.29.1 lib/decidim/api/engine.rb
decidim-api-0.28.4 lib/decidim/api/engine.rb
decidim-api-0.29.0 lib/decidim/api/engine.rb
decidim-api-0.28.3 lib/decidim/api/engine.rb
decidim-api-0.29.0.rc4 lib/decidim/api/engine.rb
decidim-api-0.29.0.rc3 lib/decidim/api/engine.rb
decidim-api-0.29.0.rc2 lib/decidim/api/engine.rb
decidim-api-0.29.0.rc1 lib/decidim/api/engine.rb
decidim-api-0.28.2 lib/decidim/api/engine.rb
decidim-api-0.28.1 lib/decidim/api/engine.rb