You can use a promise chain in your module and return the Promise object, as in the following example:
// modules/promise-sample/module.js
import axios from 'axios'
export default function () {
return axios.get('https://jsonplaceholder.typicode.com/comments')
.then(res => res.data.map(comment => '/comments/' + comment.id))
.then(routes => {
console.log(routes)
})
}
// nuxt.config.js
modules: [
['~/modules/promise-sample/module']
]
In this example, we use the get method from Axios to get all comments from the remote API. Then we use the then method to chain the Promise and print the result. You should see the following output printed to your terminal when you boot your Nuxt app for the first time:
[
'/comments/1',
'/comments/2',
'/comments/3',
...
]
You can find these two examples in /chapter-6/nuxt-universal/modules/async/ in our GitHub repository...