Skip to content

Commit

Permalink
fix(proxy): correct the logic of bypass returning false (vitejs#14579)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Oct 11, 2023
1 parent d89725b commit 261633a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/vite/src/node/server/middlewares/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
8 changes: 8 additions & 0 deletions playground/proxy-bypass/__tests__/proxy-hmr.spec.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions playground/proxy-bypass/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
root app<br />
<iframe src="/anotherApp" style="border: 0"></iframe>
11 changes: 11 additions & 0 deletions playground/proxy-bypass/package.json
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions playground/proxy-bypass/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig } from 'vite'

export default defineConfig({
server: {
port: 9606,
proxy: {
'/anotherApp': {
target: 'http://localhost:9607',
bypass: () => {
return false
},
},
},
},
})
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 261633a

Please sign in to comment.