Erstes lauffähiges Grundgerüst: Monorepo, Fastify-API, React-Startseite, Docker

This commit is contained in:
2026-07-19 01:14:29 +02:00
parent 657496fe49
commit 7b8723729b
39 changed files with 4388 additions and 15 deletions

30
apps/frontend/Dockerfile Normal file
View File

@@ -0,0 +1,30 @@
# syntax=docker/dockerfile:1
FROM node:20-alpine AS base
RUN corepack enable
WORKDIR /app
# ---- deps --------------------------------------------------------------
FROM base AS deps
COPY pnpm-workspace.yaml package.json pnpm-lock.yaml* ./
COPY packages/shared/package.json packages/shared/package.json
COPY packages/ui/package.json packages/ui/package.json
COPY apps/backend/package.json apps/backend/package.json
COPY apps/frontend/package.json apps/frontend/package.json
RUN pnpm install --frozen-lockfile || pnpm install
# ---- build ---------------------------------------------------------------
FROM deps AS build
COPY packages/shared packages/shared
COPY packages/ui packages/ui
COPY apps/frontend apps/frontend
RUN pnpm --filter @launchpad/shared build
RUN pnpm --filter @launchpad/ui build
RUN pnpm --filter @launchpad/frontend build
# ---- runtime: nginx --------------------------------------------------------
FROM nginx:1.27-alpine AS runtime
COPY apps/frontend/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/apps/frontend/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

13
apps/frontend/index.html Normal file
View File

@@ -0,0 +1,13 @@
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#0a0a0a" />
<title>LaunchPad</title>
</head>
<body class="bg-white dark:bg-black">
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

26
apps/frontend/nginx.conf Normal file
View File

@@ -0,0 +1,26 @@
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
# PWA / SPA: alle unbekannten Routen auf index.html zurückführen
location / {
try_files $uri $uri/ /index.html;
}
# API-Anfragen an den Backend-Container weiterleiten
location /api/ {
proxy_pass http://backend:3001/api/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location ~* \.(?:css|js|svg|png|jpg|jpeg|gif|ico|woff2?)$ {
expires 7d;
add_header Cache-Control "public, max-age=604800, immutable";
}
}

View File

@@ -0,0 +1,28 @@
{
"name": "@launchpad/frontend",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -p tsconfig.json --noEmit && vite build",
"preview": "vite preview --host 0.0.0.0 --port 5173",
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@launchpad/shared": "workspace:*",
"@launchpad/ui": "workspace:*",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"autoprefixer": "^10.4.20",
"postcss": "^8.4.41",
"tailwindcss": "^3.4.10",
"typescript": "^5.5.4",
"vite": "^5.4.1"
}
}

View File

@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};

124
apps/frontend/src/App.tsx Normal file
View File

@@ -0,0 +1,124 @@
import { useEffect, useRef, useState } from "react";
import { SearchInput, StatusBadge } from "@launchpad/ui";
import type { HealthStatus } from "@launchpad/shared";
type Theme = "light" | "dark";
function useTheme(): [Theme, () => void] {
const [theme, setTheme] = useState<Theme>(() => {
if (typeof window === "undefined") return "dark";
const stored = window.localStorage.getItem("launchpad-theme");
if (stored === "light" || stored === "dark") return stored;
return window.matchMedia("(prefers-color-scheme: dark)").matches
? "dark"
: "light";
});
useEffect(() => {
document.documentElement.classList.toggle("dark", theme === "dark");
window.localStorage.setItem("launchpad-theme", theme);
}, [theme]);
const toggle = () => setTheme((t) => (t === "dark" ? "light" : "dark"));
return [theme, toggle];
}
function useBackendHealth() {
const [health, setHealth] = useState<HealthStatus | null>(null);
const [error, setError] = useState(false);
useEffect(() => {
let cancelled = false;
async function check() {
try {
const res = await fetch("/api/health");
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data: HealthStatus = await res.json();
if (!cancelled) {
setHealth(data);
setError(false);
}
} catch {
if (!cancelled) setError(true);
}
}
check();
const interval = setInterval(check, 10_000);
return () => {
cancelled = true;
clearInterval(interval);
};
}, []);
return { health, error };
}
export default function App() {
const [theme, toggleTheme] = useTheme();
const [query, setQuery] = useState("");
const { health, error } = useBackendHealth();
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
function onKeyDown(e: KeyboardEvent) {
const isSlash = e.key === "/" && document.activeElement !== inputRef.current;
const isCmdK = (e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "k";
if (isSlash || isCmdK) {
e.preventDefault();
inputRef.current?.focus();
}
if (e.key === "Escape") {
inputRef.current?.blur();
setQuery("");
}
}
window.addEventListener("keydown", onKeyDown);
return () => window.removeEventListener("keydown", onKeyDown);
}, []);
const isOnline = !error && health?.status === "ok";
return (
<div className="flex min-h-screen flex-col items-center justify-center gap-8 bg-gradient-to-b from-white to-neutral-100 px-6 dark:from-black dark:to-neutral-950">
<button
onClick={toggleTheme}
aria-label="Theme wechseln"
className="fixed right-6 top-6 rounded-full border border-black/10 p-2 text-black/60
transition-colors hover:bg-black/5 dark:border-white/10 dark:text-white/60 dark:hover:bg-white/5"
>
{theme === "dark" ? "☀️" : "🌙"}
</button>
<div className="flex flex-col items-center gap-2 text-center">
<h1 className="text-4xl font-semibold tracking-tight text-black dark:text-white">
LaunchPad
</h1>
<p className="text-black/50 dark:text-white/50">
Tippe, um deine Homelab-Dienste sofort zu öffnen.
</p>
</div>
<div className="w-full max-w-xl">
<SearchInput
ref={inputRef}
value={query}
onChange={(e) => setQuery(e.target.value)}
placeholder="Dienst suchen … z. B. „frigate“"
hint="⌘K"
autoFocus
/>
</div>
<div className="flex flex-col items-center gap-1">
<StatusBadge online={isOnline} label={isOnline ? "Backend verbunden" : "Backend nicht erreichbar"} />
{health ? (
<span className="text-xs text-black/30 dark:text-white/30">
v{health.version} · läuft seit {health.uptimeSeconds}s
</span>
) : null}
</div>
</div>
);
}

View File

@@ -0,0 +1,18 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
html,
body,
#root {
height: 100%;
}
body {
font-family:
"Inter",
-apple-system,
BlinkMacSystemFont,
"Segoe UI",
sans-serif;
}

View File

@@ -0,0 +1,10 @@
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.js";
import "./index.css";
ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<App />
</React.StrictMode>
);

View File

@@ -0,0 +1,24 @@
import type { Config } from "tailwindcss";
export default {
darkMode: "class",
content: [
"./index.html",
"./src/**/*.{ts,tsx}",
"../../packages/ui/src/**/*.{ts,tsx}",
],
theme: {
extend: {
fontFamily: {
sans: [
"Inter",
"-apple-system",
"BlinkMacSystemFont",
"Segoe UI",
"sans-serif",
],
},
},
},
plugins: [],
} satisfies Config;

View File

@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Bundler",
"jsx": "react-jsx",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"types": ["vite/client"],
"noEmit": true
},
"include": ["src", "vite.config.ts"]
}

View File

@@ -0,0 +1,16 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
export default defineConfig({
plugins: [react()],
server: {
host: true,
port: 5173,
proxy: {
"/api": {
target: process.env.BACKEND_URL ?? "http://localhost:3001",
changeOrigin: true,
},
},
},
});