-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Vite's dev server returns 404 if the request does not contain an Accept header #9520
Comments
Hi all! It looks like there's a similarly related bug with the specs of A request with |
Looks like this also affects 302 redirects where |
This also effects |
Just ran into this issue and spent a good half hour tracking it down. Plz fix 🙏 |
Please add a 4-hour investigation and a full-day frustration |
This helped me as I was getting similar to OP. May be a workaround, adjust as desired. function fixAcceptHeader404() {
return {
name: 'fix-accept-header-404', // issue with vite dev server: https://github.com/vitejs/vite/issues/9520
configureServer(server) {
server.middlewares.use((req, _res, next) => {
if (req.headers.accept == 'application/json, text/plain, */*') {
req.headers.accept = '*/*';
}
next();
});
},
};
}
export default defineConfig({
plugins: [
//...
fixAcceptHeader404(),
], |
Originally from: vitejs/vite#9520 (comment)
Work around wait-on 404 error Originally from: vitejs/vite#9520 (comment)
Work around wait-on 404 error Originally from: vitejs/vite#9520 (comment)
* Install vite related libraries and uninstall react-scripts * Update package.json scripts * Create vite config * Fix index.html * Get UI to run locally * Fix eslint * Fix cypress tests * Upgrade to Cypress 12 and fix component tests * Fix cypress e2e tests * Fix middleware * Remove commented code * Ignore sonarcloud errors - The gcloud libraries are not pinned to a version so we cannot use an integrity hash here - Fontawesome no longer supports SRI hashes * Clean up unused dependencies * Use localhost instead of 127.0.0.1 Also reenable linting on server start * Fix e2e test wait-on local server Work around wait-on 404 error Originally from: vitejs/vite#9520 (comment) * Try replacing wait-on * Update to from node 14->16 Fixes build issue with vite * Remove unnecessary --production flag vite builds production by default * Use default vite react plugin config * Try defining process * Try updating jsondiffpatch version * Remove unused packages * Update .node-version * Fix cypress.config.ts * Package clean-up
Describe the bug
When making a request to Vite's dev server without adding the
Accept
header, the server always returns a 404. According to RFC 7231, theAccept
header is optional:For that reason, I would expect Vite's dev server to just respond regularly if the
Accept
header is missing.I am running into this problem when trying to use Playwright with Vite. Playwright has functionality to run a command to start the server (just calling
vite
, basically, in this case), and then polls the server URL until it receives a successful response. However, it performs the HTTP requests with a simplehttp.get
(http
from Node.js), and does not include anAccept
header, so Vite's dev server always responds with a 404 and playwright runs into a timeout waiting for the server.Reproduction
https://github.com/ghost91-/vite-dev-server-problem
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: