Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
Any fetch to a url is triggering an additional GET request to it

When I fetch with any method (POST, DELETE, etc), on any url, an additional GET request gets triggered on said url. This is a problem in the case of a DELETE /items/:id which followed by a GET /items/:id causes an error because it tries to process the related svelte page with undefined as the input data.

I tried with several pages and several methods, with console.logs at the beginning of endpoints, this behavior is always the same.

I have no hook and I don't reload the page after requests. All my fetch calls are contained within functions that can only be called via events on the DOM, so nothing is on the script's root.

Here's an example of a DELETE endpoint (I'm mainly testing against this one) :

export const DELETE = async ({params}) => {
  await meta.findOneAndDelete({url: params.url})
  return {}
}

It even occurs with this :

export const POST = async () => {
  return {}
}

I call this endpoint with a fetch(/items/${url}, {method: 'POST'}) behind a click event, and it triggers a GET /items/:url everytime. I should point out that these GET requests are not visible in the dev tools, I only see the console.logs I put in the GET endpoints and the potential errors on the server console.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It looks like these endpoints redirect to GET /items, probably to make them work nicely with HTML forms (which is funny for DELETE endpoint, since forms only support GET and POST).

You can use redirect option in your fetch call:

fetch(url, {
    method: 'POST',
    redirect: 'manual',
});

This will automatically cancel the following request.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda