Skip to content

Commit

Permalink
feat: update config of api rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzewei committed Mar 26, 2024
1 parent 6a7f0a8 commit 06cba93
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
async rewrites() {
return [
{
source: '/api/:path*',
destination: 'http://localhost:3000/api/:path*',
},
];
},
};

export default nextConfig;
2 changes: 1 addition & 1 deletion src/app/book/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function () {
const [books, setBooks] = useState<Book[]>([]);
const fetchBooks = async () => {
try {
const { data } = await fetch('http://localhost:3000/book/api/fetchBooks').then(res => res.json());
const { data } = await fetch('/book/api/fetchBooks').then(res => res.json());
setBooks(data);
} catch (err) {
console.log(err);
Expand Down

0 comments on commit 06cba93

Please sign in to comment.