Serve static assets from versioned path

This commit is contained in:
Alan Grainger
2026-07-01 08:45:03 +12:00
parent 00da9018cf
commit abd297553c
3 changed files with 34 additions and 3 deletions
+22
View File
@@ -0,0 +1,22 @@
import { readFileSync } from 'fs'
import { join } from 'path'
/**
* Resolve the running application version. Prefers the APP_VERSION env var
* baked in at Docker build time (see Dockerfile); falls back to package.json
* for local dev (`npm run dev`), and finally to 'dev' if neither is readable.
*/
function resolveVersion (): string {
if (process.env.APP_VERSION) return process.env.APP_VERSION
try {
const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'))
return pkg.version || 'dev'
} catch {
return 'dev'
}
}
export const APP_VERSION = resolveVersion()
/** URL-safe cache-busting segment for static asset paths. */
export const ASSET_VERSION = encodeURIComponent(APP_VERSION)