Models can build complex datastructures asynchronously. This is done by returning a Promise instead of a plain object. The resolved Promise should return an object.
Example asynchronous model-file /models/index.js
'use strict';
const markdown = require('itsa-react-server/lib/markdown'),
const model = async (request, reply, modelConfig, language /* , manifest */) => {
const pagecontent = await markdown.readFile('../markdowns/'+language+'/appfile-content.MD'); // asynchronous
// models need to return an object
// these objects are available at the view as `this.props`
// note that markdown returns an object like this: {__html: 'some content'}
return {
pagecontent,
count: 10
};
};