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

Unable reach Vite dev server with start-server-and-test and axios #1817

Closed
sonicoder86 opened this issue Jan 30, 2021 · 6 comments
Closed

Unable reach Vite dev server with start-server-and-test and axios #1817

sonicoder86 opened this issue Jan 30, 2021 · 6 comments

Comments

@sonicoder86
Copy link

Describe the bug

When I start my development server with Vite, it works completely fine in the browser, but querying it with axios like this axios.get('http://localhost:3000') or with the start-server-and-test package it results in 404 responses.

Here are the headers sent:

       _header: 'GET / HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'User-Agent: axios/0.21.1\r\n' +
        'Host: localhost:3000\r\n' +
        'Connection: close\r\n' +
        '\r\n',

Reproduction

It's reproducible in my repository https://github.com/blacksonic/vue-3-playground by running npm run test:e2e:javascript or starting the dev server with npm start and running node ./axios.js. Both cases return 404 errors.

System Info

  • vite version: 2.0.0-beta.56
  • Operating System: MacOS
  • Node version: v14.15.3
  • Package manager (npm/yarn/pnpm) and version: npm 6.14.9

Logs (Optional if provided reproduction)

  1. Run npm run test:e2e:javascript.
  2. Provide the error log here.
HTTP(S) error for http://localhost:3000 Error: Request failed with status code 404
making HTTP(S) get request to  url:http://localhost:3000 ...
@yyx990803
Copy link
Member

axios defaults to accept only JSON and plain text. Set your accept header to include text/html.

@sonicoder86
Copy link
Author

Is it a Vite specific setting not to accept text/plain? It works with Rollup/Webpack by default in my other repo https://github.com/blacksonic/todomvc-svelte.

I don't know if its a missing feature or a decision not to support it.

@sonicoder86
Copy link
Author

I don't know where should it be in the codebase, but I would happily contribute it if it fits the repo.

@yyx990803
Copy link
Member

It's an explicit decision because text/plain may need to go through the resolve/transform pipeline. Only text/html is exempt.

@dbousamra
Copy link

Can confirm upgrading to later version fixes this.

@sonicoder86
Copy link
Author

@dbousamra there was a fix in start-server-and-test but you still have to write http-get://localhost:3000 instead of http ://localhost:3000

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants