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

SvelteKit Redirect 308 when trying to access internal API from +page.server.ts

$
0
0

I am trying to retrieve data from a local API endpoint route within my SvelteKit application. I can confirm the endpoint works by navigating directly to it at http://localhost:5173/api/getSummary?summaryId=20 where I can see the JSON data as expected.

In a separate route - /(authenticated)/importSummary/+page.svelte - I import a component in the same directory that utilizes this API endpoint:

<script lang="ts">    export async function showInfo() {        const createSummary_response = await fetch("/api/getSummary/?summaryId=20", {            method: "GET",        });        const createSummary_response_data = await createSummary_response.json();        console.log("createSummary_response_data:", createSummary_response_data);    }</script>

This works as expected and I receive the data. My problem is when I try to access this same endpoint from a +page.server.ts, in this case at /(authenticated)/manageSummary/+page.server.ts:

import type { PageServerLoad } from './$types'export const load: PageServerLoad = async ({ fetch, params }) => {    const getSummary_response = await fetch(`/api/getSummary/?summaryId=20`, {        method: "GET",    });    const getSummary_response_data = getSummary_response;    console.log("getSummary_response_data:", getSummary_response_data);}

to which I receive the following response:

getSummary_response_data: Response {  status: 308,  statusText: '',  headers: Headers { 'x-sveltekit-normalize': '1', location: '/api/getSummary?summaryId=20' },  body: null,  bodyUsed: false,  ok: false,  redirected: false,  type: 'default',  url: ''}

Logging in my /api/getSummary/+server.ts file suggests that this endpoint is not being reached at all when fetched from the +page.server.ts.


Viewing all articles
Browse latest Browse all 1541

Trending Articles



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