Skip to content

Commit

Permalink
Fecth de produtos na Home
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniobiasotti committed Apr 23, 2024
1 parent 55a7233 commit 742a8f0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes
15 changes: 14 additions & 1 deletion src/app/(store)/(home)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import Link from "next/link";
import Image from "next/image";
import { api } from "../../../data/api";

async function getFeaturedProducts() {
const response = await api('/products/featured')

const products = await response.json()

return products
}

export default async function Home() {
const products = await getFeaturedProducts()

console.log(products)

return (
<div className="grid max-h-[860px] grid-cols-9 grid-rows-6 gap-6">
<Link
href="/"
className="group relative col-span-6 row-span-6 rounded-lg bg-zinc-900 flex justify-center items-center">

<Image
src="/moletom-never-stop-learning 1.png"
src="/moletom-never-stop-learning.png"
className="group-hover:scale-105 transition-transform duration-500"
width={920}
height={920}
Expand Down
3 changes: 2 additions & 1 deletion src/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { env } from '../env'

export function api(path: string, init?: RequestInit) {
const baseUrl = env.NEXT_PUBLIC_API_BASE_URL
const url = new URL(path, baseUrl)
const apiPrefix = '/api'
const url = new URL(apiPrefix.concat(path), baseUrl)

return fetch(url, init)
}
2 changes: 1 addition & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z } from 'zod'
import { z } from 'zod';

const envSchema = z.object({
NEXT_PUBLIC_API_BASE_URL: z.string().url(),
Expand Down

0 comments on commit 742a8f0

Please sign in to comment.