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

432
Visualizações
Sveltekit POST method not allowed on endpoint

I am trying to get this fetch method to work in Svelte

When the page.svelte calls the function to fetch the data, in the console I receive this

[HTTP/1.1 405 Method Not Allowed 19ms]

Which I have narrowed down to this

POST method not allowed

Is there a variable I need to set in the config files or is there another solution which I am missing?

// svelte.config.js

import adapter from '@sveltejs/adapter-auto';

const config = {
    kit: {
        adapter: adapter(),
        methodOverride: {
            allowed: ['POST']
        },
    }
};

export default config;

Both files are in the Routes folder

// fetch-data.js

export const POST = async(data) => {
  const response = // get data function here
  return {
    body: {
        data: response
    }
  }
}

// page.svelte

async function fetchData() {
   const response = await fetch('./fetch-data', {
     method: 'POST',
     body: JSON.stringify(),
     headers: {
       'content-type': 'application/json'
     }
   })
   const { data } = await response.json()
   return data
}
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The solution was to change the POST variable name to lowercase in the get-data.js file

about 4 years ago · Santiago Trujillo 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