blog fetch requests url updated for new env
This commit is contained in:
1 parent
a134af9f66
commit
1f5b7f3037
7 files changed
+12
-13
No files matched your search
@@ -1,2 +1,3 @@
|
||||
NEXT_PUBLIC_API_URL=http://localhost:8000/api
|
||||
NEXT_PUBLIC_BLOG_API_URL=http://localhost:8000/api/blog
|
||||
NEXT_PUBLIC_FRONT_URL=http://localhost:3000
|
||||
@@ -1,2 +1,3 @@
|
||||
NEXT_PUBLIC_API_URL=https://parsaaghayi-backend.liara.run/api
|
||||
NEXT_PUBLIC_BLOG_API_URL=https://parsaaghayi-backend.liara.run/api/blog
|
||||
NEXT_PUBLIC_FRONT_URL=https://paqi.liara.run
|
||||
@@ -10,7 +10,7 @@ export default async function SingleCategory({
|
||||
searchParams,
|
||||
}: categorySlugPropsType) {
|
||||
const categoryData: CategoryDataType = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/blog/categories/${params.categorySlug}/posts?per_page=${searchParams.per_page ? searchParams.per_page : process.env.NEXT_PUBLIC_POSTS_PER_CATEGORY_PAGE}${searchParams.page ? `&page=${searchParams.page}` : ""}`,
|
||||
`${process.env.NEXT_PUBLIC_BLOG_API_URL}/categories/${params.categorySlug}/posts?per_page=${searchParams.per_page ? searchParams.per_page : process.env.NEXT_PUBLIC_POSTS_PER_CATEGORY_PAGE}${searchParams.page ? `&page=${searchParams.page}` : ""}`,
|
||||
{
|
||||
cache: "no-store",
|
||||
},
|
||||
@@ -65,7 +65,7 @@ export default async function SingleCategory({
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div className="flex w-full flex-wrap justify-center gap-10 mb-10">
|
||||
<div className="mb-10 flex w-full flex-wrap justify-center gap-10">
|
||||
{categoryData.posts.length > 0 ? (
|
||||
categoryData.posts.map((post) => (
|
||||
<div
|
||||
|
||||
@@ -8,11 +8,9 @@ import Link from "next/link";
|
||||
import Pagination from "../components/pagination/pagination";
|
||||
import NoDataFounded from "../components/no-data-founded/noDataFounded";
|
||||
|
||||
export default async function Categories({
|
||||
searchParams,
|
||||
}: categoryPropsType) {
|
||||
export default async function Categories({ searchParams }: categoryPropsType) {
|
||||
const CategoriesData: CategoriesListType = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/blog/categories?per_page=${searchParams.per_page ? searchParams.per_page : process.env.NEXT_PUBLIC_CATEGORIES_PER_CATEGORY_PAGE}${searchParams.page ? `&page=${searchParams.page}` : ""}`,
|
||||
`${process.env.NEXT_PUBLIC_BLOG_API_URL}/categories?per_page=${searchParams.per_page ? searchParams.per_page : process.env.NEXT_PUBLIC_CATEGORIES_PER_CATEGORY_PAGE}${searchParams.page ? `&page=${searchParams.page}` : ""}`,
|
||||
{
|
||||
cache: "no-store",
|
||||
},
|
||||
|
||||
@@ -16,11 +16,10 @@ export default async function FilteredPosts({
|
||||
|
||||
switch (params.filter.replaceAll(/%20|-|_/g, " ").toLowerCase()) {
|
||||
case "new":
|
||||
filteredPostApiUrl =
|
||||
"/blog/posts?sort_field=published_at&sort_direction=desc";
|
||||
filteredPostApiUrl = "/posts?sort_field=published_at&sort_direction=desc";
|
||||
break;
|
||||
case "popular":
|
||||
filteredPostApiUrl = "/blog/posts?sort_field=views&sort_direction=desc";
|
||||
filteredPostApiUrl = "/posts?sort_field=views&sort_direction=desc";
|
||||
break;
|
||||
default:
|
||||
// code block
|
||||
@@ -31,7 +30,7 @@ export default async function FilteredPosts({
|
||||
|
||||
if (filteredPostApiUrl !== "") {
|
||||
FilteredPostsData = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}${filteredPostApiUrl}&per_page=${searchParams.per_page ? searchParams.per_page : process.env.NEXT_PUBLIC_POSTS_PER_FILTERED_POSTS_PAGE}${searchParams.page ? `&page=${searchParams.page}` : ""}`,
|
||||
`${process.env.NEXT_PUBLIC_BLOG_API_URL}${filteredPostApiUrl}&per_page=${searchParams.per_page ? searchParams.per_page : process.env.NEXT_PUBLIC_POSTS_PER_FILTERED_POSTS_PAGE}${searchParams.page ? `&page=${searchParams.page}` : ""}`,
|
||||
{
|
||||
cache: "no-store",
|
||||
},
|
||||
|
||||
@@ -9,7 +9,7 @@ export default async function Blog() {
|
||||
latest_categories: [];
|
||||
most_viewed_posts: [];
|
||||
random_posts: [];
|
||||
} = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/blog/homepage`, {
|
||||
} = await fetch(`${process.env.NEXT_PUBLIC_BLOG_API_URL}/homepage`, {
|
||||
cache: "no-store",
|
||||
}).then((res) => res.json());
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ import { redirect } from "next/navigation";
|
||||
|
||||
export default async function SinglePost({ params }: PostSlugPagepropsType) {
|
||||
const postData: PostSlugPagePostType = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/blog/posts/${params.postSlug}`,
|
||||
`${process.env.NEXT_PUBLIC_BLOG_API_URL}/posts/${params.postSlug}`,
|
||||
{
|
||||
cache: "no-store",
|
||||
},
|
||||
).then((res) => {
|
||||
if (res.status == 404) {
|
||||
redirect("/blog/404")
|
||||
redirect("/blog/404");
|
||||
}
|
||||
return res.json();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user