From 09a949092c59856962e4a7d132bc5a5e76fe5e55 Mon Sep 17 00:00:00 2001 From: ertopogo Date: Sun, 18 Jan 2026 20:32:59 +0100 Subject: Initial commit: Medusa Backend + storefront + config --- storefront/Dockerfile | 35 +++++++++++++++++++++++++++++++++++ storefront/lib/medusa-client.js | 6 ++++++ storefront/next.config.js | 10 ++++++++++ storefront/package.json | 31 +++++++++++++++++++++++++++++++ storefront/pages/_app.js | 17 +++++++++++++++++ storefront/pages/index.js | 26 ++++++++++++++++++++++++++ 6 files changed, 125 insertions(+) create mode 100644 storefront/Dockerfile create mode 100644 storefront/lib/medusa-client.js create mode 100644 storefront/next.config.js create mode 100644 storefront/package.json create mode 100644 storefront/pages/_app.js create mode 100644 storefront/pages/index.js (limited to 'storefront') diff --git a/storefront/Dockerfile b/storefront/Dockerfile new file mode 100644 index 0000000..b6c1da8 --- /dev/null +++ b/storefront/Dockerfile @@ -0,0 +1,35 @@ +# Install dependencies only when needed +FROM node:18-alpine AS deps +WORKDIR /app +COPY package.json yarn.lock* package-lock.json* ./ +RUN npm ci + +# Rebuild the source code only when needed +FROM node:18-alpine AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . +# Disable telemetry during build +ENV NEXT_TELEMETRY_DISABLED 1 +RUN npm run build + +# Production image, copy all the files and run next +FROM node:18-alpine AS runner +WORKDIR /app +ENV NODE_ENV production +ENV NEXT_TELEMETRY_DISABLED 1 + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs + +EXPOSE 8000 +ENV PORT 8000 + +CMD ["node", "server.js"] + diff --git a/storefront/lib/medusa-client.js b/storefront/lib/medusa-client.js new file mode 100644 index 0000000..0b78f76 --- /dev/null +++ b/storefront/lib/medusa-client.js @@ -0,0 +1,6 @@ +import Medusa from "@medusajs/medusa-js" + +const BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL || "http://localhost:9000" + +export const medusaClient = new Medusa({ baseUrl: BACKEND_URL, maxRetries: 3 }) + diff --git a/storefront/next.config.js b/storefront/next.config.js new file mode 100644 index 0000000..255e46c --- /dev/null +++ b/storefront/next.config.js @@ -0,0 +1,10 @@ +/** @type {import('next').NextConfig} */ +const nextConfig = { + reactStrictMode: true, + images: { + domains: ["localhost", "medusa-public-images.s3.eu-west-1.amazonaws.com"], + }, +} + +module.exports = nextConfig + diff --git a/storefront/package.json b/storefront/package.json new file mode 100644 index 0000000..fefa31c --- /dev/null +++ b/storefront/package.json @@ -0,0 +1,31 @@ +{ + "name": "medusa-storefront", + "version": "1.0.0", + "private": true, + "scripts": { + "dev": "next dev -p 8000", + "build": "next build", + "start": "next start -p 8000", + "lint": "next lint" + }, + "dependencies": { + "@medusajs/medusa": "^1.20.0", + "@medusajs/medusa-js": "^6.1.7", + "@tanstack/react-query": "4.22.0", + "medusa-react": "^9.0.15", + "next": "13.4.12", + "react": "18.2.0", + "react-dom": "18.2.0", + "clsx": "^2.0.0", + "lucide-react": "^0.263.1" + }, + "devDependencies": { + "autoprefixer": "^10.4.14", + "postcss": "^8.4.27", + "tailwindcss": "^3.3.3", + "typescript": "5.1.6", + "@types/react": "18.2.18", + "@types/node": "20.4.9" + } +} + diff --git a/storefront/pages/_app.js b/storefront/pages/_app.js new file mode 100644 index 0000000..1424c52 --- /dev/null +++ b/storefront/pages/_app.js @@ -0,0 +1,17 @@ +import { MedusaProvider } from "medusa-react" +import { QueryClient } from "@tanstack/react-query" +import { medusaClient } from "../lib/medusa-client" + +const queryClient = new QueryClient() + +export default function App({ Component, pageProps }) { + return ( + + + + ) +} + diff --git a/storefront/pages/index.js b/storefront/pages/index.js new file mode 100644 index 0000000..fa4a592 --- /dev/null +++ b/storefront/pages/index.js @@ -0,0 +1,26 @@ +import { useProducts } from "medusa-react" + +export default function Home() { + const { products, isLoading } = useProducts() + + return ( +
+

Bienvenue sur la boutique Lucien-sens-bon

+ {isLoading && Chargement des produits...} + +
+ {products && products.map((product) => ( +
+

{product.title}

+

{product.description}

+
+ ))} +
+ + {!isLoading && !products?.length && ( +

Aucun produit trouvé. Connectez-vous à l'admin pour en ajouter !

+ )} +
+ ) +} + -- cgit v1.2.3