Redirects vs Rewrites

seojm·2023년 1월 28일

공통점

next.config.js 파일 내에 작성해야하며, 서버를 재시작해야 적용된다. 둘 다 pattern matching을 지원하고 객체 배열을 return 해야한다.

redirects

next.config.js에서 이루어짐

async redirects() {
	return [
		{
			source: "/old",
			destination: "/new",
			permanent: false,
		},
	];
}

pattern matching 지원.

rewrites

	async rewrites() {
		return [
			{
				source: "/api/movies",
				destination: `https://api.themoviedb.org/3/movie/popular?api_key=${API_KEY}`,
			},
		];
	}

destination으로 redirect 돼도 URL에 표시되지 않아 API key와 같이 숨겨야 할 정보들을 숨길 수 있음.

profile
'너무 많아 걱정'

0개의 댓글