mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 22:59:10 +00:00
fix(proxy): correct the logic of bypass returning false (#14579)
This commit is contained in:
parent
d89725b1a4
commit
261633a1a1
@ -154,7 +154,8 @@ export function proxyMiddleware(
|
||||
return next()
|
||||
} else if (bypassResult === false) {
|
||||
debug?.(`bypass: ${req.url} -> 404`)
|
||||
return res.end(404)
|
||||
res.statusCode = 404
|
||||
return res.end()
|
||||
}
|
||||
}
|
||||
|
||||
|
8
playground/proxy-bypass/__tests__/proxy-hmr.spec.ts
Normal file
8
playground/proxy-bypass/__tests__/proxy-hmr.spec.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { expect, test, vi } from 'vitest'
|
||||
import { browserLogs } from '~utils'
|
||||
|
||||
test('proxy-bypass', async () => {
|
||||
await vi.waitFor(() => {
|
||||
expect(browserLogs.join('\n')).toContain('status of 404 (Not Found)')
|
||||
})
|
||||
})
|
2
playground/proxy-bypass/index.html
Normal file
2
playground/proxy-bypass/index.html
Normal file
@ -0,0 +1,2 @@
|
||||
root app<br />
|
||||
<iframe src="/anotherApp" style="border: 0"></iframe>
|
11
playground/proxy-bypass/package.json
Normal file
11
playground/proxy-bypass/package.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "@vitejs/test-proxy-bypass",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
}
|
||||
}
|
15
playground/proxy-bypass/vite.config.js
Normal file
15
playground/proxy-bypass/vite.config.js
Normal file
@ -0,0 +1,15 @@
|
||||
import { defineConfig } from 'vite'
|
||||
|
||||
export default defineConfig({
|
||||
server: {
|
||||
port: 9606,
|
||||
proxy: {
|
||||
'/anotherApp': {
|
||||
target: 'http://localhost:9607',
|
||||
bypass: () => {
|
||||
return false
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
@ -1030,6 +1030,8 @@ importers:
|
||||
|
||||
playground/preserve-symlinks/module-a: {}
|
||||
|
||||
playground/proxy-bypass: {}
|
||||
|
||||
playground/proxy-hmr: {}
|
||||
|
||||
playground/proxy-hmr/other-app: {}
|
||||
|
Loading…
Reference in New Issue
Block a user