I wrote an application using nuxtjs and I'm using SSR. The approach of fetching data from asyncdata function on server I've seen online always suggest that I make that API request from the server to itself. eg
export default {
async asyncData({ params, $http }) {
const post = await $http.$get(`www.myserver.com/api/resource`)
return { post }
}}
I know this will work but for performance and latency issues, I see no reason why we should route the internet twice just to render one page.
So my question is, how can I manually forward a request to my API routes without hitting the internet again in express?
One Approach is importing my database modules to this vue file and doing all dependency injection stuff. This seems inappropriate though.
What I want to do is something like
import apimodule from './apimodule.js'
const data = apimodule.handle(request)
return {data}
Thanks.