Initial commit: installable PWA hello world

React + TypeScript + Tailwind v4 + shadcn/ui frontend (client), Express +
better-sqlite3 backend (server) in a pnpm workspace. Includes vite-plugin-pwa
manifest, service worker, and iOS install meta tags. GET /api/hello increments a
visit counter in SQLite; backend serves the built client in production.
This commit is contained in:
2026-08-03 22:45:19 +02:00
commit 3785d08e97
38 changed files with 8405 additions and 0 deletions

35
server/src/db.ts Normal file
View File

@@ -0,0 +1,35 @@
import Database from "better-sqlite3"
import fs from "node:fs"
import path from "node:path"
import { fileURLToPath } from "node:url"
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const dataDir = path.resolve(__dirname, "../data")
fs.mkdirSync(dataDir, { recursive: true })
const dbPath = path.join(dataDir, "app.db")
export const db = new Database(dbPath)
db.pragma("journal_mode = WAL")
db.exec(`
CREATE TABLE IF NOT EXISTS visits (
id INTEGER PRIMARY KEY CHECK (id = 1),
count INTEGER NOT NULL DEFAULT 0
)
`)
const existing = db
.prepare("SELECT count FROM visits WHERE id = 1")
.get() as { count: number } | undefined
if (!existing) {
db.prepare("INSERT INTO visits (id, count) VALUES (1, 0)").run()
}
export function incrementAndGetVisits(): number {
db.prepare("UPDATE visits SET count = count + 1 WHERE id = 1").run()
const row = db.prepare("SELECT count FROM visits WHERE id = 1").get() as { count: number }
return row.count
}

32
server/src/index.ts Normal file
View File

@@ -0,0 +1,32 @@
import express from "express"
import fs from "node:fs"
import path from "node:path"
import { fileURLToPath } from "node:url"
import { helloRouter } from "./routes/hello.js"
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const app = express()
const PORT = process.env.PORT ? Number(process.env.PORT) : 3001
app.use(express.json())
app.get("/api/health", (_req, res) => {
res.json({ ok: true })
})
app.use("/api", helloRouter)
// In production, serve the built client (client/dist) and fall back to index.html.
const clientDist = path.resolve(__dirname, "../../client/dist")
if (fs.existsSync(clientDist)) {
app.use(express.static(clientDist))
app.get("*", (_req, res) => {
res.sendFile(path.join(clientDist, "index.html"))
})
}
app.listen(PORT, () => {
console.log(`Pocket Pascal server listening on http://localhost:${PORT}`)
})

View File

@@ -0,0 +1,14 @@
import { Router } from "express"
import { incrementAndGetVisits } from "../db.js"
export const helloRouter = Router()
helloRouter.get("/hello", (_req, res) => {
const visits = incrementAndGetVisits()
res.json({
message: "Hello, World!",
visits,
ts: new Date().toISOString(),
})
})