This commit is contained in:
2026-03-23 19:14:25 -05:00
parent 92676e652a
commit 58ac75e51b
11 changed files with 202 additions and 20 deletions

View File

@@ -0,0 +1,9 @@
node_modules
dist
.git
.gitignore
README.md
npm-debug.log
server/node_modules
server/.env
.env

View File

@@ -0,0 +1,4 @@
SITE_HOST=example.com
POSTGRES_DB=pottery_db
POSTGRES_USER=pottery
POSTGRES_PASSWORD=change-this-password

10
Pottery-website/Caddyfile Normal file
View File

@@ -0,0 +1,10 @@
{$SITE_HOST:localhost} {
encode zstd gzip
@api path /api/* /health
reverse_proxy @api backend:5000
root * /srv
try_files {path} /index.html
file_server
}

View File

@@ -0,0 +1,12 @@
FROM node:22-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build:docker
FROM caddy:2-alpine
COPY Caddyfile /etc/caddy/Caddyfile
COPY --from=build /app/dist /srv

View File

@@ -116,3 +116,29 @@ Access the dashboard by navigating to `/admin`.
--- ---
**Crafted with care by Antigravity.** **Crafted with care by Antigravity.**
## Docker Deployment with Caddy
For a self-hosted deployment, this repository now includes:
- `Dockerfile.frontend`: Builds the Vite frontend and serves it with Caddy.
- `server/Dockerfile`: Runs the Node/Express API.
- `docker-compose.yml`: Starts Caddy, the API, and PostgreSQL together.
- `server/init.sql`: Initializes the database schema on first startup.
### Quick Start
1. Copy `.env.example` to `.env`.
2. Set `SITE_HOST` to your domain name.
3. Set a strong `POSTGRES_PASSWORD`.
4. Start the stack:
```bash
docker compose up -d --build
```
### Notes
- Caddy terminates TLS automatically when `SITE_HOST` points to a public domain with correct DNS.
- The frontend uses `/api` in production, and Caddy proxies that path to the backend container.
- PostgreSQL data is stored in the `postgres_data` Docker volume.

View File

@@ -0,0 +1,63 @@
services:
caddy:
build:
context: .
dockerfile: Dockerfile.frontend
container_name: pottery-caddy
depends_on:
backend:
condition: service_healthy
environment:
SITE_HOST: ${SITE_HOST}
ports:
- "80:80"
- "443:443"
volumes:
- caddy_data:/data
- caddy_config:/config
restart: unless-stopped
backend:
build:
context: ./server
dockerfile: Dockerfile
container_name: pottery-backend
depends_on:
db:
condition: service_healthy
environment:
PORT: 5000
DB_USER: ${POSTGRES_USER}
DB_HOST: db
DB_NAME: ${POSTGRES_DB}
DB_PASSWORD: ${POSTGRES_PASSWORD}
DB_PORT: 5432
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:5000/health"]
interval: 10s
timeout: 5s
retries: 10
start_period: 15s
db:
image: postgres:16-alpine
container_name: pottery-db
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
- ./server/init.sql:/docker-entrypoint-initdb.d/00-init.sql:ro
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 10
volumes:
postgres_data:
caddy_data:
caddy_config:

View File

@@ -6,6 +6,7 @@
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vite build", "build": "vite build",
"build:docker": "vite build",
"postbuild": "react-snap", "postbuild": "react-snap",
"preview": "vite preview" "preview": "vite preview"
}, },

View File

@@ -0,0 +1,11 @@
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
EXPOSE 5000
CMD ["node", "index.js"]

View File

@@ -25,6 +25,16 @@ pool.on('error', (err) => {
process.exit(-1); process.exit(-1);
}); });
app.get('/health', async (_req, res) => {
try {
await pool.query('SELECT 1');
res.json({ ok: true });
} catch (err) {
console.error('Healthcheck failed', err);
res.status(500).json({ ok: false });
}
});
// Routes // Routes
// --- PRODUCTS --- // --- PRODUCTS ---

View File

@@ -0,0 +1,36 @@
CREATE TABLE IF NOT EXISTS products (
id SERIAL PRIMARY KEY,
title VARCHAR(255) NOT NULL,
price DECIMAL(10, 2) NOT NULL,
image TEXT NOT NULL,
description TEXT,
gallery JSONB DEFAULT '[]'::jsonb,
slug TEXT,
number TEXT,
aspect_ratio TEXT,
details JSONB DEFAULT '[]'::jsonb
);
CREATE TABLE IF NOT EXISTS articles (
id SERIAL PRIMARY KEY,
title VARCHAR(255) NOT NULL,
date VARCHAR(50) NOT NULL,
image TEXT NOT NULL,
sections JSONB DEFAULT '[]'::jsonb,
slug TEXT,
category TEXT,
description TEXT,
is_featured BOOLEAN DEFAULT FALSE
);
CREATE TABLE IF NOT EXISTS orders (
id SERIAL PRIMARY KEY,
customer_email TEXT NOT NULL,
customer_name TEXT NOT NULL,
shipping_address JSONB NOT NULL,
items JSONB NOT NULL,
total_amount DECIMAL(10, 2) NOT NULL,
payment_status TEXT DEFAULT 'pending',
shipping_status TEXT DEFAULT 'pending',
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

View File

@@ -43,7 +43,7 @@ interface StoreContextType {
const StoreContext = createContext<StoreContextType | undefined>(undefined); const StoreContext = createContext<StoreContextType | undefined>(undefined);
const API_URL = 'http://localhost:5000/api'; const API_URL = import.meta.env.VITE_API_URL || '/api';
export const StoreProvider: React.FC<{ children: ReactNode }> = ({ children }) => { export const StoreProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
const [products, setProducts] = useState<CollectionItem[]>([]); const [products, setProducts] = useState<CollectionItem[]>([]);
@@ -97,8 +97,8 @@ export const StoreProvider: React.FC<{ children: ReactNode }> = ({ children }) =
]); ]);
const prods = await prodRes.json(); const prods = await prodRes.json();
const arts = await artRes.json(); const arts = await artRes.json();
setProducts(prods); setProducts(Array.isArray(prods) && prods.length > 0 ? prods : COLLECTIONS);
setArticles(arts); setArticles(Array.isArray(arts) && arts.length > 0 ? arts : JOURNAL_ENTRIES);
} catch (err) { } catch (err) {
console.error('Failed to fetch data from backend, falling back to static data', err); console.error('Failed to fetch data from backend, falling back to static data', err);
setProducts(COLLECTIONS); setProducts(COLLECTIONS);