Files
fullhouse/server/index.js
Fredrik Johansson dc90e7404b
All checks were successful
Docker / build-and-push (push) Successful in 46s
Serve Spotify client ID from /api/config instead of baking it in at build
Was a Vite build-time env var, requiring a second copy of a non-secret
value as a separate Gitea CI secret alongside the one already in .env
for the api service. Client id isn't sensitive (public in every
Spotify authorize URL), so it doesn't need build-time baking at all —
now fetched once from a new GET /api/config on the already-running api
server, cached client-side after the first call.

Collapses config back down to the one place it already lived
(the deploy host's .env / docker-compose environment), removes the
CI build-arg and its secret entirely.

Verified end-to-end: /api/config returns the real client id, and a
live guest-login click correctly carries it through into the actual
Spotify authorize URL (decoded and checked, not just assumed from the
code).
2026-07-18 22:15:13 +02:00

33 lines
1.1 KiB
JavaScript

import 'dotenv/config';
import express from 'express';
import cookieParser from 'cookie-parser';
import hostAuth from './routes/hostAuth.js';
import hostPlaylists from './routes/hostPlaylists.js';
import publicPlaylist from './routes/publicPlaylist.js';
import session from './routes/session.js';
const app = express();
app.use(cookieParser());
app.use(express.json());
app.get('/api/health', (req, res) => res.json({ ok: true }));
// Spotify's client id is not sensitive (it's public in every authorize
// URL, visible in any browser network tab) — served here instead of
// baked into the client at build time so the whole app has exactly one
// place to configure it (this server's own .env), not a second copy as
// a separate CI build-arg/secret.
app.get('/api/config', (req, res) => {
res.json({ clientId: process.env.SPOTIFY_CLIENT_ID });
});
app.use('/api/spotify', hostAuth);
app.use('/api/host', hostPlaylists);
app.use('/api/public-playlist', publicPlaylist);
app.use('/api/session', session);
const PORT = process.env.PORT || 3010;
app.listen(PORT, () => {
console.log(`fullhouse API listening on :${PORT}`);
});