Is there a method to exclusively retrieve data from an API on the server-side in NuxtJS due to me needing to include my API_TOKEN
in the request headers?
Sample Code:
<template>
<div>
<h1>Data obtained using asyncData</h1>
<ul>
<li v-for="mountain in mountains" :key="mountain.title">
<NuxtLink
:to="{ name: 'mountains-slug', params: { slug: mountain.slug } }"
>
{{ mountain.title }}
</NuxtLink>
</li>
</ul>
</div>
</template>
<script>
export default {
async asyncData({ $http }) {
const mountains = await $http.$get('https://api.nuxtjs.dev/mountains', {headers: "X-API-KEY: MY_API_TOKEN"})
return { mountains }
}
}
</script>