import axios from 'axios'

export default {
  getRoutes: async () => {
    // We can fetch any data we want, however we want!
    const { data: posts } = await axios.get('https://jsonplaceholder.typicode.com/posts')

    // Components in the 'pages' directory are automatically added as routes.
    // But...
    return [
      {
        // We still need to supply the 'posts' data to our blog route
        path: 'blog',
        getData: () => ({
          posts,
        }),
        // And generate a route/component for each individual blog post
        children: posts.map(post => ({
          path: `blog/post/${post.id}`,
          component: 'Post',
          getData: () => ({
            post,
          }),
        })),
      },
    ]
  },
}
