Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Sveltekit - Form Action - fetch Post api using different port

$
0
0

I have a front end local server using port 5173. I have a rest api backend on localhost but using different port, like port 3422. Is it possible to use Sveltekit Form Action if my front end running on 5173, but I want to send my request to 3422?

Debugging my form action gives me 500 because it uses http://localhost:5173/. What did I miss?

export const actions = {    default: async ({ request }) => {    const formData = await request.formData()    const param3 = formData.get('param3')    const param4 = formData.get('param4')    const param5 = formData.get('param5')    const response = await fetch(import.meta.env.VITE_URL, {      method: 'POST',      headers: {'Content-Type': 'application/json',      },      body: JSON.stringify({        attr3: param3,        attr4: param4,        attr5: 10      })    });    const res = await response.json();    return res;  return {    success: true,  }}}Using it on html side simply: <form method="POST">

Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>