Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Keep the seller panel's build directory on Spree::Dashboard

Damian Legawiecf86fb3d21449
diff --git a/spree/core/app/finders/spree/sellers/panel_url.rb b/spree/core/app/finders/spree/sellers/panel_url.rb
index 633319b1a2..79435cef91 100644
--- a/spree/core/app/finders/spree/sellers/panel_url.rb
+++ b/spree/core/app/finders/spree/sellers/panel_url.rb
@@ -3,63 +3,45 @@ module Spree
# Origin where the seller panel is hosted, for links that send a seller
# into it — today the invitation email.
#
- # Deliberately its own resolver rather than a branch inside
- # `Spree::Stores::DashboardUrl`: the two are different apps for different
- # audiences, and the dashboard's fallback chain (the `/dashboard` mount
- # this app serves, the Vite dev server on 5173) names origins where no
- # seller panel is running.
- #
# Resolution order, most authoritative first:
#
# 1. the `seller_panel_url` preference / SPREE_SELLER_PANEL_URL
# 2. the `/sellers` mount this app serves, when a bundle is configured
- # 3. the dashboard origin, as a last resort
- #
- # The last fallback is deliberate but imperfect, and worth understanding.
- # A seller who follows it lands on the staff dashboard's acceptance page,
- # which authenticates through the Admin API: accepting there DOES join them
- # to the seller (the invitation's role is what creates membership), but the
- # session it issues carries the `admin_api` audience, so they cannot use
- # the seller panel with it and must sign in again once one exists.
- #
- # Kept rather than raising because the alternative is worse: a marketplace
- # that has not deployed a panel yet would be unable to invite anyone at
- # all, and the invitation still needs to reach a page that can accept it.
- # Configure SPREE_SELLER_PANEL_URL, or serve the bundle at `/sellers`, and
- # this branch is never taken. A warning is logged when it is.
+ # 3. the dashboard origin, as a last resort — accepting there joins the
+ # seller but issues an admin session, so they must sign in again once a
+ # panel exists. Kept rather than raising: a marketplace that has not
+ # deployed one yet still needs to invite people.
class PanelUrl
# @param store [Spree::Store, nil] store whose URL ends the fallback chain
- # @return [String] origin without a trailing slash, e.g. +https://sellers.shop.com+
+ # @return [String] origin without a trailing slash
def self.call(store: nil)
configured = Spree::Config[:seller_panel_url].presence
-
return configured.to_s.chomp('/') if configured
- mounted = mounted_panel_url(store)
- return mounted if mounted
-
- Rails.logger.warn(
- '[Spree] No seller panel is configured, so seller invitations point at the staff ' \
- 'dashboard. Accepting there joins the seller but issues an admin session, not a ' \
- 'seller one. Set SPREE_SELLER_PANEL_URL or serve a seller panel build at /sellers.'
- )
-
- Spree::Stores::DashboardUrl.call(store: store)
+ mounted_panel_url(store) || dashboard_fallback(store)
end
# The `/sellers` mount this app serves, when `spree_dashboard` is
# installed AND pointed at a seller-panel build. Without a bundle the
# route 404s, so linking there would be worse than the dashboard.
- # @return [String, nil]
def self.mounted_panel_url(store)
- return unless defined?(Spree::SellerPanel) && Spree::SellerPanel.dist_path.present?
+ return unless defined?(Spree::Dashboard) && Spree::Dashboard.seller_panel_dist_path.present?
host = Spree::Stores::DashboardUrl.app_host(store)
- return if host.blank?
-
- "#{host.chomp('/')}/sellers"
+ "#{host.chomp('/')}/sellers" if host.present?
end
private_class_method :mounted_panel_url
+
+ def self.dashboard_fallback(store)
+ Rails.logger.warn(
+ '[Spree] No seller panel is configured, so seller invitations point at the staff ' \
+ 'dashboard. Accepting there joins the seller but issues an admin session, not a ' \
+ 'seller one. Set SPREE_SELLER_PANEL_URL or serve a seller panel build at /sellers.'
+ )
+
+ Spree::Stores::DashboardUrl.call(store: store)
+ end
+ private_class_method :dashboard_fallback
end
end
end
diff --git a/spree/core/spec/finders/spree/sellers/panel_url_spec.rb b/spree/core/spec/finders/spree/sellers/panel_url_spec.rb
index 604720de15..261caf6940 100644
--- a/spree/core/spec/finders/spree/sellers/panel_url_spec.rb
+++ b/spree/core/spec/finders/spree/sellers/panel_url_spec.rb
@@ -22,13 +22,13 @@ RSpec.describe Spree::Sellers::PanelUrl do
end
# The single-node topology: Spree serves the panel itself at /sellers, so a
- # link there works without any hostname of its own. `Spree::SellerPanel`
+ # link there works without any hostname of its own. `Spree::Dashboard`
# ships in the optional spree_dashboard gem, which core's suite does not
# load — hence the resolver's `defined?` guard, and this stand-in.
context 'when this app serves a seller panel bundle' do
before do
- stub_const('Spree::SellerPanel', Module.new do
- def self.dist_path = '/tmp/panel-dist'
+ stub_const('Spree::Dashboard', Module.new do
+ def self.seller_panel_dist_path = '/tmp/panel-dist'
end)
end
diff --git a/spree/dashboard/app/controllers/spree/seller_panel/app_controller.rb b/spree/dashboard/app/controllers/spree/seller_panel/app_controller.rb
index 08b7e56d71..93cf99f6c8 100644
--- a/spree/dashboard/app/controllers/spree/seller_panel/app_controller.rb
+++ b/spree/dashboard/app/controllers/spree/seller_panel/app_controller.rb
@@ -3,20 +3,15 @@ module Spree
# Serves the built marketplace seller panel at /sellers.
#
# Same origin as the dashboard and the API on purpose: the two panels'
- # refresh cookies are already isolated by name and path
- # (`/api/v3/admin/auth` vs `/api/v3/seller/auth`), so sharing a host costs
- # nothing in isolation and saves every deployment a second hostname and
- # certificate. A marketplace that wants sellers on their own domain
- # deploys the bundle there and points SPREE_SELLER_PANEL_URL at it.
- #
- # The dist directory comes from `Spree::SellerPanel.dist_path`; when
- # unset, /sellers 404s — a marketplace that runs no seller panel serves
- # nothing rather than an empty shell.
+ # refresh cookies are already isolated by name and path, so sharing a host
+ # saves every deployment a second hostname and certificate. A marketplace
+ # that wants sellers on their own domain deploys the bundle there and
+ # points SPREE_SELLER_PANEL_URL at it.
class AppController < Spree::Dashboard::SpaController
private
def dist_path
- Spree::SellerPanel.dist_path
+ Spree::Dashboard.seller_panel_dist_path
end
end
end
diff --git a/spree/dashboard/lib/spree/dashboard.rb b/spree/dashboard/lib/spree/dashboard.rb
index 21bbfa5006..6b177edf35 100644
--- a/spree/dashboard/lib/spree/dashboard.rb
+++ b/spree/dashboard/lib/spree/dashboard.rb
@@ -12,11 +12,19 @@ module Spree
def dist_path
@dist_path.presence || ENV.fetch('SPREE_DASHBOARD_DIST_PATH', nil)
end
+
+ # Directory holding a built marketplace seller panel, served at
+ # /sellers. A separate bundle rather than the dashboard's: it is a
+ # different app — its own entry point, router and API client — so
+ # pointing both mounts at one directory would serve sellers the
+ # operator's back office. Unset, /sellers responds 404.
+ attr_writer :seller_panel_dist_path
+
+ def seller_panel_dist_path
+ @seller_panel_dist_path.presence || ENV.fetch('SPREE_SELLER_PANEL_DIST_PATH', nil)
+ end
end
end
end
-# The seller panel rides in this gem: same engine, same SPA-serving
-# controller, a different bundle at a different mount.
-require 'spree/seller_panel'
require 'spree/dashboard/engine'
diff --git a/spree/dashboard/lib/spree/seller_panel.rb b/spree/dashboard/lib/spree/seller_panel.rb
deleted file mode 100644
index 058e088bc5..0000000000
--- a/spree/dashboard/lib/spree/seller_panel.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-require 'spree'
-
-module Spree
- module SellerPanel
- class << self
- # Directory holding a built seller panel (`vite build` output), served
- # at /sellers. Set from an initializer, or via the
- # SPREE_SELLER_PANEL_DIST_PATH env var. Unset, /sellers responds 404 —
- # a marketplace that runs no seller panel serves nothing.
- attr_writer :dist_path
-
- def dist_path
- @dist_path.presence || ENV.fetch('SPREE_SELLER_PANEL_DIST_PATH', nil)
- end
- end
- end
-end
diff --git a/spree/dashboard/spec/requests/spree/seller_panel/app_spec.rb b/spree/dashboard/spec/requests/spree/seller_panel/app_spec.rb
index 3b1fd60138..3bfa85af30 100644
--- a/spree/dashboard/spec/requests/spree/seller_panel/app_spec.rb
+++ b/spree/dashboard/spec/requests/spree/seller_panel/app_spec.rb
@@ -11,7 +11,7 @@ RSpec.describe 'Hosted seller panel', type: :request do
after do
FileUtils.remove_entry(dist)
- Spree::SellerPanel.dist_path = nil
+ Spree::Dashboard.seller_panel_dist_path = nil
Spree::Dashboard.dist_path = nil
end
@@ -25,7 +25,7 @@ RSpec.describe 'Hosted seller panel', type: :request do
end
context 'when a bundle is configured' do
- before { Spree::SellerPanel.dist_path = dist }
+ before { Spree::Dashboard.seller_panel_dist_path = dist }
it 'serves the shell at the mount root' do
get '/sellers'
@@ -62,7 +62,7 @@ RSpec.describe 'Hosted seller panel', type: :request do
# other, or a marketplace with no seller panel would hand sellers the
# operator's dashboard.
it 'does not serve the dashboard bundle' do
- Spree::SellerPanel.dist_path = nil
+ Spree::Dashboard.seller_panel_dist_path = nil
Spree::Dashboard.dist_path = dist
get '/sellers'