import axios from 'axios'

//

const routeSize = 10

if (!process.env.REACT_STATIC_SLAVE) {
  console.log()
  console.log(`Testing ${routeSize} routes`)
}

export default {
  getRoutes: async () => {
    const { data: posts } = await axios.get('https://jsonplaceholder.typicode.com/posts')

    const allPosts = []

    while (allPosts.length < routeSize) {
      allPosts.push({
        ...posts[Math.floor(Math.random() * posts.length)],
        id: allPosts.length,
      })
    }

    return [
      {
        path: '/blog',
        getData: () => ({
          posts,
        }),
        children: allPosts.map(post => ({
          path: `/post/${post.id}`,
          component: 'src/containers/Post',
          getData: () => ({
            post,
          }),
        })),
      },
    ]
  },
}
