NuxtN
Nuxt17mo ago
25 replies
Baljeet Singh

runtimeConfig not working when website deployed to netlify

I have a server route called api/youtube-video

export default defineEventHandler(async () => {
  // Fetch runtime configuration
  const runtimeConfig = useRuntimeConfig();

  // Fetch data from YouTube API
  const data = $fetch(
    `https://youtube.googleapis.com/youtube/v3/search?part=snippet&channelId=UCeWvxihiyzB_ic84VWxHVnA&channelType=any&maxResults=50&order=date&key=${runtimeConfig.youtubeApiKey}`
  );

  // Return the videos
  return data;
});


.env
YOUTUBE_API_KEY=key


nuxt.config.ts
runtimeConfig: {
    youtubeApiKey: process.env.YOUTUBE_API_KEY,
  },



This is working fine on local.

But, when i deploy the website to netlify. The api doesn't return any data..
https://www.baljeetsingh.in/videos

I have added YOUTUBE_API_KEY in the netlify environment variables too.

am i missing something?
image.png
Was this page helpful?