Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix redirect not working #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const debug = _debug('vite-plugin-inspect')
// initial tranform (load from fs)
const dummyLoadPluginName = '__load__'

const CLIENT_ROUTE = '/__inspect'

export interface Options {
/**
* Enable the inspect plugin in dev mode (could be some performance overhead)
Expand Down Expand Up @@ -230,7 +232,13 @@ export default function PluginInspect(options: Options = {}): Plugin {
return _invalidateModule.apply(this, args)
}

server.middlewares.use('/__inspect', sirv(DIR_CLIENT, {
server.middlewares.use((req, res, next) => {
if (req.originalUrl?.includes(CLIENT_ROUTE))
req.url = req.originalUrl
next()
})

server.middlewares.use(CLIENT_ROUTE, sirv(DIR_CLIENT, {
single: true,
dev: true,
}))
Expand Down Expand Up @@ -300,7 +308,7 @@ export default function PluginInspect(options: Options = {}): Plugin {
const host = server.resolvedUrls?.local[0] || `${config.server.https ? 'https' : 'http'}://localhost:${config.server.port || '80'}/`
_print()
// eslint-disable-next-line no-console
console.log(` ${green('➜')} ${bold('Inspect')}: ${colorUrl(`${host}__inspect/`)}\n`)
console.log(` ${green('➜')} ${bold('Inspect')}: ${colorUrl(`${host}${CLIENT_ROUTE}/`)}\n`)
}
}

Expand Down