getServerSideProps で複数のurlを取得する方法です。
こんな感じにプログラム書きます。
//SSR用
export async function getServerSideProps(ctx) {
//contextが、サーバ側に表示されます。
console.log(ctx);
const profileDataReq = axios({
method: 'GET',
url: 'https://xxx.jp/api/tdnet1/',
});
const bookmarksReq = axios({
method: 'GET',
url: 'https://xxx.jp/api/tdnet2/',
});
const [profile, bookmarks] = await Promise.all([
profileDataReq,
bookmarksReq
]);
return {
props: {
profile: profile.data,
bookmarks: bookmarks.data
}
};
};
//本体
export default function Index(props) {
console.log(props);
return (
<div className="container pt-5 my-5 "></div>
)
}
とまぁ、こんな風にプログラムを書くと、Next.jsでSSRで運用が可能になります。