Sha256: f46e49a58a474430ad223709a1adba3bae737c5ada8403a20f8439bea9f7075c

Contents?: true

Size: 996 Bytes

Versions: 6

Compression:

Stored size: 996 Bytes

Contents

# frozen_string_literal: true

require "graphql"
require "graphiql/rails"
require "rack/cors"
require "sprockets/es6"

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.assets" do |app|
        app.config.assets.precompile += %w(decidim_api_manifest.js decidim_api_manifest.css)
      end

      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
        GraphiQL::Rails.config.tap do |config|
          config.query_params = true
          config.initial_query = File.read(
            File.join(__dir__, "graphiql-initial-query.txt")
          ).html_safe
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-api-0.24.3 lib/decidim/api/engine.rb
decidim-api-0.24.2 lib/decidim/api/engine.rb
decidim-api-0.24.1 lib/decidim/api/engine.rb
decidim-api-0.24.0 lib/decidim/api/engine.rb
decidim-api-0.24.0.rc2 lib/decidim/api/engine.rb
decidim-api-0.24.0.rc1 lib/decidim/api/engine.rb