Next.js Discord

Discord Forum

Cors missing allow origin

Unanswered
Korat posted this in #help-forum
Open in Discord
KoratOP
Hello,
I have a nextjs app and backend using kotlin
backend runs on localhost:12345
fromtend runs on localhost:3000

now whenever i use fetch to get results from the backend i get hit with a cors missing allow origin error

how can i fix it?

import { GenerateBoardResponse } from '@/types/types';

const baseURL = process.env.NEXT_PUBLIC_BACKEND_URL;

export async function fetchGenerateBoard(dimension: number): Promise<GenerateBoardResponse> {
    const response = await fetch(`${baseURL}/board/generate?dimension=${dimension}`, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        }
    });

    if (!response.ok) {
        throw new Error('Failed to fetch board');
    }

    return response.json();
}

0 Replies