feat: expose backend url in admin options (#7370)

This commit is contained in:
Oli Juhl
2024-05-20 11:24:15 +02:00
committed by GitHub
parent 028f63eb63
commit c9bffdfecb
3 changed files with 8 additions and 7 deletions

View File

@@ -17,6 +17,8 @@ export async function getViteConfig(
const root = path.resolve(__dirname, "./")
const backendUrl = options.backendUrl ?? ""
return {
root: path.resolve(__dirname, "./"),
base: options.path,
@@ -29,12 +31,7 @@ export async function getViteConfig(
},
define: {
__BASE__: JSON.stringify(options.path),
/**
* TODO: Accept backend url from config to support hosting the admin elsewhere.
* The empty string should be the default value, as that ensures that requests
* are made to the server that serves the admin dashboard.
*/
__BACKEND_URL__: JSON.stringify(""),
__BACKEND_URL__: JSON.stringify(backendUrl),
},
server: {
open: true,

View File

@@ -1,4 +1,4 @@
import { AdminOptions } from "@medusajs/types"
export type BundlerOptions = Required<Pick<AdminOptions, "outDir" | "path">> &
Pick<AdminOptions, "vite">
Pick<AdminOptions, "vite" | "backendUrl">

View File

@@ -33,6 +33,10 @@ export type AdminOptions = {
* The default value is `./build`.
*/
outDir?: string
/**
* The URL of your Medusa server. Defaults to an empty string, which means requests will hit the same server that serves the dashboard.
*/
backendUrl?: string
/**
* Configure the Vite configuration for the admin dashboard. This function receives the default Vite configuration
* and returns the modified configuration. The default value is `undefined`.