Set up Siteforge container deployment and registry publishing

This commit is contained in:
Nate Emmert
2026-03-17 15:15:33 -04:00
commit 695f124afe
27 changed files with 6432 additions and 0 deletions
+62
View File
@@ -0,0 +1,62 @@
import express from 'express'
import { mkdir, readFile, writeFile } from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const DATA_DIR = path.join(__dirname, 'data')
const DATA_FILE = path.join(DATA_DIR, 'admin-content.json')
const DIST_DIR = path.join(__dirname, 'dist')
const INDEX_FILE = path.join(DIST_DIR, 'index.html')
const app = express()
app.use(express.json({ limit: '2mb' }))
app.get('/api/admin-content', async (_req, res) => {
try {
const raw = await readFile(DATA_FILE, 'utf8')
const parsed = JSON.parse(raw)
res.json(parsed)
} catch {
res.status(404).json({ message: 'No saved admin content file yet.' })
}
})
app.put('/api/admin-content', async (req, res) => {
try {
const { projects, siteContent } = req.body ?? {}
if (!Array.isArray(projects) || !siteContent || typeof siteContent !== 'object') {
res.status(400).json({ message: 'Invalid payload.' })
return
}
await mkdir(DATA_DIR, { recursive: true })
await writeFile(
DATA_FILE,
JSON.stringify({ projects, siteContent, updatedAt: new Date().toISOString() }, null, 2),
'utf8',
)
res.json({ ok: true })
} catch {
res.status(500).json({ message: 'Failed to persist admin content.' })
}
})
app.use(express.static(DIST_DIR))
app.get('*', async (_req, res) => {
try {
const html = await readFile(INDEX_FILE, 'utf8')
res.type('html').send(html)
} catch {
res.status(503).send('Frontend build not found. Run "npm run build" first.')
}
})
const PORT = Number(process.env.PORT ?? 4173)
app.listen(PORT, () => {
console.log(`Portfolio app listening on http://localhost:${PORT}`)
})