@spree/cli 2.4.1 → 2.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
#
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
|
|
1
|
+
# Dev-server proxy target — where Vite forwards /api and /rails (your
|
|
2
|
+
# Rails backend). The SPA stays same-origin with the API: the SDK uses
|
|
3
|
+
# relative URLs and the proxy bridges the port gap.
|
|
4
|
+
#
|
|
5
|
+
# Do NOT set VITE_SPREE_API_URL for local dev — it switches the SDK to
|
|
6
|
+
# absolute cross-origin URLs, which breaks on CORS and the SameSite=Lax
|
|
7
|
+
# auth cookie. Set it only when building for a deploy where the
|
|
8
|
+
# dashboard is hosted on a different origin than the API.
|
|
9
|
+
#
|
|
10
|
+
# No credentials belong in this file — every VITE_-prefixed value is
|
|
11
|
+
# compiled into the client bundle.
|
|
12
|
+
VITE_API_PROXY_TARGET=http://localhost:3000
|
|
@@ -8,10 +8,12 @@ The host app for the [Spree React Dashboard](https://spreecommerce.org/docs/deve
|
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
pnpm install
|
|
11
|
-
cp .env.example .env.local #
|
|
11
|
+
cp .env.example .env.local # optional — VITE_API_PROXY_TARGET if your API isn't on :3000
|
|
12
12
|
pnpm dev # http://localhost:5173
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
The dev server proxies `/api` to your Rails backend so the SPA stays same-origin — don't set `VITE_SPREE_API_URL` in dev (it switches the SDK to absolute cross-origin URLs, which breaks on CORS and the auth cookie).
|
|
16
|
+
|
|
15
17
|
Sign in with an admin account — authentication is interactive (JWT + refresh cookie). No API keys belong in `.env.local`: every `VITE_`-prefixed value is compiled into the client bundle.
|
|
16
18
|
|
|
17
19
|
## Install a dashboard plugin
|
|
@@ -1,33 +1,36 @@
|
|
|
1
1
|
import { spreeDashboardPlugin } from '@spree/dashboard/vite'
|
|
2
2
|
import react from '@vitejs/plugin-react'
|
|
3
|
-
import { defineConfig } from 'vite'
|
|
3
|
+
import { defineConfig, loadEnv } from 'vite'
|
|
4
4
|
|
|
5
|
-
export default defineConfig({
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
5
|
+
export default defineConfig(({ mode }) => {
|
|
6
|
+
// loadEnv, not process.env: Vite doesn't load .env files before evaluating
|
|
7
|
+
// this config, and .env.local is where `spree` writes the proxy target.
|
|
8
|
+
const env = loadEnv(mode, process.cwd(), 'VITE_')
|
|
9
|
+
const proxyTarget = env.VITE_API_PROXY_TARGET || 'http://localhost:3000'
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
// Sub-path mounting for the single-node topology (Rails serves the build
|
|
13
|
+
// at /dashboard): build with VITE_BASE_PATH=/dashboard/ so asset URLs
|
|
14
|
+
// resolve. Unset (dev, CDN root deploys) Vite defaults to '/'.
|
|
15
|
+
base: process.env.VITE_BASE_PATH,
|
|
16
|
+
// spreeDashboardPlugin bundles Tailwind, injects @source directives for
|
|
17
|
+
// every Spree dashboard package, auto-discovers installed dashboard
|
|
18
|
+
// plugins (package.json deps carrying the `spree.dashboard.plugin`
|
|
19
|
+
// marker), serves the `virtual:spree-dashboard-plugins` module that
|
|
20
|
+
// src/main.tsx imports to activate them, and composes the shell's and
|
|
21
|
+
// every plugin's file routes into src/routeTree.gen.ts on each dev
|
|
22
|
+
// start/build — commit that file; its diff shows what an upgrade added.
|
|
23
|
+
plugins: [spreeDashboardPlugin(), react()],
|
|
24
|
+
// Proxy /api to the Rails server so the SPA is same-origin with the API
|
|
25
|
+
// in dev — keeps the refresh-token cookie working under SameSite=Lax
|
|
26
|
+
// without HTTPS. /rails covers Active Storage's presigned URLs. Proxy
|
|
27
|
+
// target, not VITE_SPREE_API_URL — that switches the SDK to absolute
|
|
28
|
+
// cross-origin URLs and bypasses this proxy (see .env.example).
|
|
29
|
+
server: {
|
|
30
|
+
proxy: {
|
|
31
|
+
'/api': { target: proxyTarget, changeOrigin: true },
|
|
32
|
+
'/rails': { target: proxyTarget, changeOrigin: true },
|
|
30
33
|
},
|
|
31
34
|
},
|
|
32
|
-
}
|
|
35
|
+
}
|
|
33
36
|
})
|