Skip to content

Commit

Permalink
fix(vite): prepend base on devtools POST_PATH (#2836)
Browse files Browse the repository at this point in the history
  • Loading branch information
flipace committed Jul 8, 2023
1 parent 5d70124 commit 95f9c93
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/vite/src/devtool.ts
Expand Up @@ -21,7 +21,7 @@ const MODULES_MAP: Record<string, string | undefined> = {
[MOCK_CLASSES_MODULE_ID]: MOCK_CLASSES_PATH,
}

const POST_PATH = '/@unocss-devtools-update'
const BASE_POST_PATH = '/@unocss-devtools-update'

function getBodyJson(req: IncomingMessage) {
return new Promise<any>((resolve, reject) => {
Expand All @@ -45,6 +45,7 @@ export function createDevtoolsPlugin(ctx: UnocssPluginContext): Plugin[] {
let clientCode = ''
let devtoolTimer: any
let lastUpdate = Date.now()
let postPath = BASE_POST_PATH

function toClass(name: string) {
// css escape
Expand Down Expand Up @@ -91,13 +92,14 @@ export function createDevtoolsPlugin(ctx: UnocssPluginContext): Plugin[] {

configResolved(_config) {
config = _config
postPath = `${(config.base?.replace(/\/$/, '') ?? '')}${BASE_POST_PATH}`
},

configureServer(_server) {
server = _server

server.middlewares.use(async (req, res, next) => {
if (req.url !== POST_PATH)
if (req.url !== postPath)
return next()

try {
Expand Down Expand Up @@ -141,7 +143,7 @@ export function createDevtoolsPlugin(ctx: UnocssPluginContext): Plugin[] {
`import('${DEVTOOLS_CSS_PATH}')`,
]
.join('\n')
.replace('__POST_PATH__', (config.server?.origin ?? '') + POST_PATH)
.replace('__POST_PATH__', `${(config.server?.origin ?? '')}${postPath}`)
}
return config.command === 'build'
? ''
Expand Down

0 comments on commit 95f9c93

Please sign in to comment.