Eptagone / Vite.AspNetCore

Small library to integrate Vite into ASP.NET projects
MIT License
264 stars 35 forks source link

Vite won't respond to request without "Accept" header #31

Closed triforcely closed 1 year ago

triforcely commented 1 year ago

Hey, first of all you made a great project.

I tried setting it up today but I have an issue, where proxied page is blank. I started debugging, and found an issue and I have a minimal repro.

When doing plain HTTP GET to Vite, it responds with 404, this is what happens on page load.

obraz

tt can be reproduced with this minimal code:

using var client = new HttpClient
{
    BaseAddress = new Uri("http://localhost:5173")
};

var res = await client.GetAsync("/");

Which is very similar to what we have here https://github.com/Eptagone/Vite.AspNetCore/blob/722fb6421ef9a640c5d1063e9f3b32d3c76510de/src/Vite.AspNetCore/Services/ViteDevMiddleware.cs#LL179C18-L179C18

I'm not sure if this is some new behavior in Vite (v4.3.9 ) but I'm willing to create a PR to fix this case.

Eptagone commented 1 year ago

Hello, i can't reproduce this issue. Do you have an example repository?

Eptagone commented 1 year ago

I couldn't reproduce the messages, but I think it should redirect the Accept header like you do so I accept the pull request, Thanks @triforcely.

Maybe I should forward the other headers, hmm. Well, I'll see what I do.

triforcely commented 1 year ago

@Eptagone I just create a new vue project with npm create vite@latest my-vue-app -- --template vue . This error was seen when I started Vite with debug option ("-d").

triforcely commented 1 year ago

My fix was merged but if you really want to see this behaviour, you can repro it like this:

1) Create new project with: npm create vite@latest my-vue-app -- --template vue-ts 2) Start the project with debug flag, so you can see fallback error log: npm run dev -- -d 3) Create a console c# app with following code:

using var client = new HttpClient
{
    BaseAddress = new Uri("http://localhost:5173")
};

var res = await client.GetAsync("/");

4) Get

 vite:html-fallback Not rewriting GET / because the client did not send an HTTP accept header. +1m
  vite:time 0.35ms / +1m
  vite:html-fallback Not rewriting GET / because the client did not send an HTTP accept header. +10s
  vite:time 0.28ms / +10s

Also, I could repro it with Postman but I had to explicitly tell it to not send "Accept" header.