0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

getServerSideProps で複数のurlを取得する方法

Last updated at Posted at 2022-10-04

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で運用が可能になります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?