Files
medusa-store/packages/admin-ui/webpack.config.dev.ts
Rick Lam b4e8adfcf9 fix(admin-ui): Admin UI: Invalid Request Header (#5548)
**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>
2023-11-09 12:32:27 +00:00

58 lines
1.6 KiB
TypeScript

import { DuplicateReporterPlugin } from "duplicate-dependencies-webpack-plugin"
import path from "path"
import openBrowser from "react-dev-utils/openBrowser"
import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer"
import { Configuration } from "webpack-dev-server"
import { getWebpackConfig } from "./src/node/webpack/get-webpack-config"
const getDevServerConfig = () => {
const analyzeBundle = process.env.ANALYZE_BUNDLE
const analyzeDuplicateDependencies = process.env.ANALYZE_DEPS
const devConfig = getWebpackConfig({
cacheDir: __dirname,
dest: path.resolve(__dirname, "build"),
entry: path.resolve(__dirname, "ui", "src", "main.tsx"),
env: "development",
options: {
backend: "http://localhost:9000",
path: "/",
},
template: path.resolve(__dirname, "ui", "index.html"),
publicFolder: path.resolve(__dirname, "ui", "public"),
})
if (analyzeBundle) {
devConfig.plugins?.push(new BundleAnalyzerPlugin())
}
if (analyzeDuplicateDependencies === "true") {
devConfig.plugins?.push(new DuplicateReporterPlugin())
}
return {
...devConfig,
...{
devServer: {
port: 7001,
hot: true,
historyApiFallback: true,
client: {
progress: false,
},
static: {
directory: path.resolve(__dirname, "./ui/public"),
publicPath: "/",
},
open: false,
onListening: function () {
openBrowser(`http://localhost:7001`)
},
allowedHosts: 'auto',
} as Configuration,
},
}
}
module.exports = getDevServerConfig()