diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d20c676fa..4da39eeec 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "open-uri" + class ApplicationController < ActionController::API include ActionController::HttpAuthentication::Basic::ControllerMethods include Authenticable @@ -164,6 +166,28 @@ def skip_bullet Bullet.enable = previous_value end + def serve_manifest + url = ENV["PLUGIN_MANIFEST_URL"] || "https://api.datacite.org" + data = URI.open(url).read + + send_data( + data, + type: "application/json", + disposition: "inline" + ) + end + + def serve_openapi_spec + url = ENV["PLUGIN_OPENAPI_URL"] || "https://api.datacite.org" + data = URI.open(url).read + + send_data( + data, + type: "text/yaml", + disposition: "inline" + ) + end + protected def is_admin_or_staff? current_user&.is_admin_or_staff? ? 1 : 0 diff --git a/config/routes.rb b/config/routes.rb index f1b42826f..84da67052 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,6 +18,10 @@ # send reset link post "reset", to: "sessions#reset" + ## to route when requesting .well-known/ai-plugin.json to route to that file + get "/.well-known/ai-plugin.json", to: "application#serve_manifest" + get "/graphql-openapi.yaml", to: "application#serve_openapi_spec" + # content negotiation via index path get "/application/vnd.datacite.datacite+xml/:id", to: "index#show", @@ -244,6 +248,7 @@ constraints: { id: /.+/ }, format: false + root to: "index#index" # rescue routing errors