N
Nuxt5mo ago
Neamix

Get api domain in nitro server file

Greeting i created server route that go to api and check the phone if it exist before or not here it's
export default defineEventHandler(async (event) => {
let config = useRuntimeConfig();
let domain = config.public.apiURL;
let route = domain+'/api/user/phone/count';
const body = await readBody(event);
return await $fetch(route, {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: 'post',
body: {
phone: body.phone,
countryCode: body.countryCode
}
})
})
export default defineEventHandler(async (event) => {
let config = useRuntimeConfig();
let domain = config.public.apiURL;
let route = domain+'/api/user/phone/count';
const body = await readBody(event);
return await $fetch(route, {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: 'post',
body: {
phone: body.phone,
countryCode: body.countryCode
}
})
})
and here it my env file
apiURL=https://app.rifq.me
apiURL=https://app.rifq.me
every thing is cool on local but on production i got File not found error (Note: api route is same on local and prod)
1 Reply
Neamix
NeamixOP5mo ago
i am using forge to deploy but the main script that forge use is that
cd /home/forge/www.rifq.me
git pull origin $FORGE_SITE_BRANCH

npm ci
npm run generate

( flock -w 10 9 || exit 1
echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock
cd /home/forge/www.rifq.me
git pull origin $FORGE_SITE_BRANCH

npm ci
npm run generate

( flock -w 10 9 || exit 1
echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock
the api route is right on both local and prod but for some reason on production he cant use it i printed it in console and deploy and viewed the production and i found that he read the right url and i also tried ur approch and still have same issue
Want results from more Discord servers?
Add your server