diff --git a/app/controllers/embed_scripts_controller.rb b/app/controllers/embed_scripts_controller.rb new file mode 100644 index 00000000..874c21f3 --- /dev/null +++ b/app/controllers/embed_scripts_controller.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +class EmbedScriptsController < ActionController::Metal + DUMMY_SCRIPT = <<~JAVASCRIPT.freeze + const DummyBuilder = class extends HTMLElement { + connectedCallback() { + this.innerHTML = ` +
+ `; + } + }; + + const DummyForm = class extends DummyBuilder {}; + + if (!window.customElements.get('docuseal-builder')) { + window.customElements.define('docuseal-builder', DummyBuilder); + } + + if (!window.customElements.get('docuseal-form')) { + window.customElements.define('docuseal-form', DummyForm); + } + JAVASCRIPT + + def show + headers['Content-Type'] = 'application/javascript' + + self.response_body = DUMMY_SCRIPT + + self.status = 200 + end +end diff --git a/config/routes.rb b/config/routes.rb index a3e90fc8..7874959f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -166,5 +166,7 @@ Rails.application.routes.draw do end end + get '/js/:filename', to: 'embed_scripts#show', as: :embed_script + ActiveSupport.run_load_hooks(:routes, self) end