**What** Fix of https://github.com/medusajs/medusa/issues/4904 **Fixes** Admin run development server with hostname shown Invalid Request Header **How** Added webpack-dev-server config [allowedHosts](https://webpack.js.org/configuration/dev-server/#devserverallowedhosts) and [webSocketUrl](https://webpack.js.org/configuration/dev-server/#websocketurl) in admin develop options to change allowlist services hostname and Web Socket Url **Testing** Edit medusa-config.js with hostname in admin plugin develop options ``` const plugins = [ // ... { resolve: "@medusajs/admin", /** @type {import('@medusajs/admin').PluginOptions} */ options: { develop: { allowedHosts: [ 'host.com', 'subdomain.host.com', 'subdomain2.host.com', 'host2.com', ], webSocketURL: 'wss://host.com/ws' }, }, }, ] ``` Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
62 lines
1.6 KiB
TypeScript
62 lines
1.6 KiB
TypeScript
import type { ConfigModule } from "@medusajs/medusa"
|
|
import { getConfigFile } from "medusa-core-utils"
|
|
import { PluginOptions } from "../types"
|
|
|
|
export const loadConfig = (isDev?: boolean): PluginOptions | null => {
|
|
const { configModule } = getConfigFile<ConfigModule>(
|
|
process.cwd(),
|
|
"medusa-config"
|
|
)
|
|
|
|
const plugin = configModule.plugins.find(
|
|
(p) =>
|
|
(typeof p === "string" && p === "@medusajs/admin") ||
|
|
(typeof p === "object" && p.resolve === "@medusajs/admin")
|
|
)
|
|
|
|
if (!plugin) {
|
|
return null
|
|
}
|
|
|
|
let config: PluginOptions = {
|
|
serve: true,
|
|
autoRebuild: false,
|
|
path: isDev ? "/" : "/app",
|
|
outDir: "build",
|
|
backend: isDev ? "http://localhost:9000" : "/",
|
|
develop: {
|
|
open: true,
|
|
port: 7001,
|
|
allowedHosts: 'auto',
|
|
},
|
|
}
|
|
|
|
if (typeof plugin !== "string") {
|
|
const options = (plugin as { options: PluginOptions }).options ?? {}
|
|
|
|
const serve = options.serve !== undefined ? options.serve : config.serve
|
|
|
|
const serverUrl = serve
|
|
? config.backend
|
|
: options.backend
|
|
? options.backend
|
|
: "/"
|
|
|
|
config = {
|
|
serve,
|
|
autoRebuild: options.autoRebuild ?? config.autoRebuild,
|
|
path: options.path ?? config.path,
|
|
outDir: options.outDir ?? config.outDir,
|
|
backend: serverUrl,
|
|
develop: {
|
|
open: options.develop?.open ?? config.develop.open,
|
|
port: options.develop?.port ?? config.develop.port,
|
|
allowedHosts: options.develop?.allowedHosts ?? config.develop.allowedHosts,
|
|
webSocketURL: options.develop?.webSocketURL ?? config.develop.webSocketURL,
|
|
},
|
|
}
|
|
}
|
|
|
|
return config
|
|
}
|