Class: SpreeMenuChat::ChatController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- SpreeMenuChat::ChatController
- Includes:
- ActionController::Live, Spree::Core::ControllerHelpers::Store
- Defined in:
- app/controllers/spree_menu_chat/chat_controller.rb
Overview
Streams (M4 — SSE) the storefront widget's answer. The Next.js Route
Handler proxy (src/app/api/chat/route.ts in spree_storefront_web)
calls this directly and streams the response through unmodified; the
browser never calls this controller itself.
Bare ActionController::Base, not the host app's ApplicationController — same reasoning as SpreeSquare::WebhooksController: this is a small, isolated endpoint that shouldn't inherit the host's session/layout/ devise stack.
Authenticated with the store's Storefront publishable key
(X-Spree-Api-Key, a pk_... token), the same key type spree_api's
Store API v3 accepts — not admin/secret-key auth, since this is a
customer-facing, read-only endpoint. Deliberately hand-rolled rather
than including Spree::Api::V3::ApiKeyAuthentication: that concern's
error rendering is coupled to that engine's own Api::V3::ErrorHandler,
which this controller doesn't otherwise use.
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
34 35 36 37 38 39 |
# File 'app/controllers/spree_menu_chat/chat_controller.rb', line 34 def create question = params[:question].to_s.strip return render_error('Question is required', status: :unprocessable_entity) if question.blank? stream_answer(question) end |