fix(proxy): correct the logic of bypass returning false (#14579)

This commit is contained in:
Dunqing 2023-10-11 02:07:24 -05:00 committed by GitHub
parent d89725b1a4
commit 261633a1a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 1 deletions

View File

@ -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()
}
}

View 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)')
})
})

View File

@ -0,0 +1,2 @@
root app<br />
<iframe src="/anotherApp" style="border: 0"></iframe>

View 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"
}
}

View File

@ -0,0 +1,15 @@
import { defineConfig } from 'vite'
export default defineConfig({
server: {
port: 9606,
proxy: {
'/anotherApp': {
target: 'http://localhost:9607',
bypass: () => {
return false
},
},
},
},
})

View File

@ -1030,6 +1030,8 @@ importers:
playground/preserve-symlinks/module-a: {}
playground/proxy-bypass: {}
playground/proxy-hmr: {}
playground/proxy-hmr/other-app: {}