Next.js Discord

Discord Forum
\n I am not familar with next js (only svelte) so sorry if it's a basic question. I was not able to find any working solution. I even added the following in next js config file headers: async () => {\n return [\n {\n // mathching all API routes\n source: \"/api/:path*\",\n headers: [\n { key: \"Access-Control-Allow-Credentials\", value: \"true\" },\n { key: \"Access-Control-Allow-Origin\", value: \"*\" },\n {\n key: \"Access-Control-Allow-Methods\",\n value: \"GET,OPTIONS,PATCH,DELETE,POST,PUT\",\n },\n {\n key: \"Access-Control-Allow-Headers\",\n value: \"X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version\",\n },\n ],\n },\n ];\n },","dateCreated":"2024-09-16T12:24:16.698Z","answerCount":8,"author":{"@type":"Person","name":"Cuban Crocodile"},"suggestedAnswer":{"@type":"Answer","text":"Bump","url":"https://nextjs-forum.com/post/1285214675184783421#message-1285636102333399191","dateCreated":"2024-09-17T16:18:52.760Z","author":{"@type":"Person","name":"Cuban Crocodile"}}}}

cors issue with next js & fumadocs (CORS Allow Origin Not Matching Origin)

Unanswered
Cuban Crocodile posted this in #help-forum
Open in Discord
Avatar
Cuban CrocodileOP
Hello! I am facing issue when embedding self hosted umami in fumadocs layout file (in body tag)

            <body>
                <RootProvider>{children}</RootProvider>

                <script
                    defer
                    src="https://domain.something.tld/script.js"
                    data-website-id="id"
                ></script>
            </body>


I am not familar with next js (only svelte) so sorry if it's a basic question. I was not able to find any working solution. I even added the following in next js config file

    headers: async () => {
        return [
            {
                // mathching all API routes
                source: "/api/:path*",
                headers: [
                    { key: "Access-Control-Allow-Credentials", value: "true" },
                    { key: "Access-Control-Allow-Origin", value: "*" },
                    {
                        key: "Access-Control-Allow-Methods",
                        value: "GET,OPTIONS,PATCH,DELETE,POST,PUT",
                    },
                    {
                        key: "Access-Control-Allow-Headers",
                        value: "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version",
                    },
                ],
            },
        ];
    },
Image

8 Replies

Avatar
Cuban CrocodileOP
Bump
Avatar
Cuban CrocodileOP
@fuma 💙 joulev could you help me out? Sorry for the ping :/
Someone suggested i make redirect but the script.js calls that api endpoint
Avatar
this is irrelevant to Fumadocs, it's about Next.js and CORS. You need to provide more info
Avatar
Cuban CrocodileOP
i am integrating umami into fumadocs (umami is a self hosted analytics like google analytics )
So for starters i added the following to wiki/app/layout.tsx
export default function Layout({ children }: { children: ReactNode }) {
    return (
        <html lang="en" className={inter.className} suppressHydrationWarning>
            <body>
                <RootProvider>{children}</RootProvider>

                <script
                    defer
                    src="https://analytics.domain.tld/script.js"
                    data-website-id="id"
                ></script>
            </body>
        </html>
    );
}
but umami script.js calls an external endpoint, which is giving the cors issue