ignacio
ignacio
TTCTheo's Typesafe Cult
Created by cailloubleu on 8/10/2023 in #questions
How to fetch local API with App Router
I had the same problem you just need to create a function getbaseurl that you concat in the begining of your fetch request:
export function getBaseUrl() {
if (typeof window !== 'undefined') return '';
const vc = process.env.VERCEL_URL;
if (vc) return `https://${vc}`;
return 'http://localhost:8081';
}
export function getBaseUrl() {
if (typeof window !== 'undefined') return '';
const vc = process.env.VERCEL_URL;
if (vc) return `https://${vc}`;
return 'http://localhost:8081';
}
9 replies
TTCTheo's Typesafe Cult
Created by ignacio on 8/3/2023 in #questions
T3 - app dir - tRPC + Prisma + Custom auth
Plus when I try to use the createPost action on a client side I can't pass data properly:
import { createPost } from '~/app/actions';

/// ... ///

const onSubmit = handleSubmit(async (data) => {
try {
reset();
console.log('DATA', data);
if (data) {
const post = await createPost({ text: data.text });
console.log('post', post);
// ======== HERE ==========
// always get the error

}
} catch (error) {
console.error(error);
}
});
import { createPost } from '~/app/actions';

/// ... ///

const onSubmit = handleSubmit(async (data) => {
try {
reset();
console.log('DATA', data);
if (data) {
const post = await createPost({ text: data.text });
console.log('post', post);
// ======== HERE ==========
// always get the error

}
} catch (error) {
console.error(error);
}
});
3 replies