Skip to content

Commit ebe7016

Browse files
2.2 Redirect and Rewrite
1 parent c27afcd commit ebe7016

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ yarn-error.log*
3232

3333
# vercel
3434
.vercel
35+
.env

next.config.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
const API_KEY = process.env.API_KEY;
2+
13
module.exports = {
24
reactStrictMode: true,
3-
}
5+
async redirects() {
6+
return [
7+
{
8+
source: "/old-blog/:path*",
9+
destination: "/new-sexy-blog/:path*",
10+
permanent: false,
11+
},
12+
];
13+
},
14+
async rewrites() {
15+
return [
16+
{
17+
source: "/api/movies",
18+
destination: `https://api.themoviedb.org/3/movie/popular?api_key=${API_KEY}`,
19+
},
20+
];
21+
},
22+
};

pages/index.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,45 @@
11
import { useEffect, useState } from "react";
22
import Seo from "../components/Seo";
33

4-
const API_KEY = "10923b261ba94d897ac6b81148314a3f";
5-
64
export default function Home() {
75
const [movies, setMovies] = useState();
86
useEffect(() => {
97
(async () => {
10-
const { results } = await (
11-
await fetch(
12-
`https://api.themoviedb.org/3/movie/popular?api_key=${API_KEY}`
13-
)
14-
).json();
8+
const { results } = await (await fetch(`/api/movies`)).json();
159
setMovies(results);
1610
})();
1711
}, []);
1812
return (
19-
<div>
13+
<div className="container">
2014
<Seo title="Home" />
2115
{!movies && <h4>Loading...</h4>}
2216
{movies?.map((movie) => (
23-
<div key={movie.id}>
17+
<div className="movie" key={movie.id}>
18+
<img src={`https://image.tmdb.org/t/p/w500/${movie.poster_path}`} />
2419
<h4>{movie.original_title}</h4>
2520
</div>
2621
))}
22+
<style jsx>{`
23+
.container {
24+
display: grid;
25+
grid-template-columns: 1fr 1fr;
26+
padding: 20px;
27+
gap: 20px;
28+
}
29+
.movie img {
30+
max-width: 100%;
31+
border-radius: 12px;
32+
transition: transform 0.2s ease-in-out;
33+
box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 12px;
34+
}
35+
.movie:hover img {
36+
transform: scale(1.05) translateY(-10px);
37+
}
38+
.movie h4 {
39+
font-size: 18px;
40+
text-align: center;
41+
}
42+
`}</style>
2743
</div>
2844
);
2945
}

0 commit comments

Comments
 (0)