Localhost:3000 says: Failed to run middleware with uploadthing

The only way I could resolve my errors in the this file was the following:
import { clerkMiddleware } from '@clerk/nextjs/server';
import { NextResponse } from 'next/server';

export default clerkMiddleware(
(auth, req) => {
try {
if (!req.nextUrl) {
throw new Error('req.nextUrl is undefined');
}
const url = req.nextUrl;
const searchParams = url.searchParams.toString();

if (!req.headers || !req.headers.get) {
throw new Error('req.headers is undefined or does not have get method');
}
const hostname = req.headers.get('host');
if (!hostname) {
throw new Error('Hostname is not present in req.headers');
}
const pathWithSearchParams = `${url.pathname}${searchParams.length > 0 ? `?${searchParams}` : ''}`;

const customSubDomain = hostname.split(`${process.env.NEXT_PUBLIC_DOMAIN}`).filter(Boolean)[0];

if (customSubDomain) {
return NextResponse.rewrite(new URL(`/${customSubDomain}${pathWithSearchParams}`, req.url));
}

//I have more logic here, but maxed out the character count

} catch (error) {
console.error('Error:', error.message);
return NextResponse.error();
}
}
);

export const config = {
matcher: ['/((?!.+\\.[\\w]+$|_next).*)', '/', '/(api|trpc)(.*)'],
};
import { clerkMiddleware } from '@clerk/nextjs/server';
import { NextResponse } from 'next/server';

export default clerkMiddleware(
(auth, req) => {
try {
if (!req.nextUrl) {
throw new Error('req.nextUrl is undefined');
}
const url = req.nextUrl;
const searchParams = url.searchParams.toString();

if (!req.headers || !req.headers.get) {
throw new Error('req.headers is undefined or does not have get method');
}
const hostname = req.headers.get('host');
if (!hostname) {
throw new Error('Hostname is not present in req.headers');
}
const pathWithSearchParams = `${url.pathname}${searchParams.length > 0 ? `?${searchParams}` : ''}`;

const customSubDomain = hostname.split(`${process.env.NEXT_PUBLIC_DOMAIN}`).filter(Boolean)[0];

if (customSubDomain) {
return NextResponse.rewrite(new URL(`/${customSubDomain}${pathWithSearchParams}`, req.url));
}

//I have more logic here, but maxed out the character count

} catch (error) {
console.error('Error:', error.message);
return NextResponse.error();
}
}
);

export const config = {
matcher: ['/((?!.+\\.[\\w]+$|_next).*)', '/', '/(api|trpc)(.*)'],
};
But when I try to upload a file using uploadthing dropbox, I get "failed to run middleware" Any ideas how to resolve this? Thanks in advance!
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server