6 changed files with 90 additions and 13 deletions
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
import { readFileSync } from 'fs'; |
||||
import { join } from 'path'; |
||||
import type { RequestHandler } from '@sveltejs/kit'; |
||||
|
||||
export const GET: RequestHandler = async () => { |
||||
try { |
||||
// Try multiple possible locations for changelog.yaml
|
||||
// 1. In public directory (development)
|
||||
// 2. In build/client (production - where SvelteKit copies public files)
|
||||
// 3. In the copied public directory (Docker)
|
||||
const possiblePaths = [ |
||||
join(process.cwd(), 'public', 'changelog.yaml'), |
||||
join(process.cwd(), 'build', 'client', 'changelog.yaml'), |
||||
join(process.cwd(), '..', 'public', 'changelog.yaml'), |
||||
'/app/public/changelog.yaml' // Docker container path
|
||||
]; |
||||
|
||||
let changelogContent: string | null = null; |
||||
for (const path of possiblePaths) { |
||||
try { |
||||
changelogContent = readFileSync(path, 'utf-8'); |
||||
break; // Found it, stop trying
|
||||
} catch { |
||||
// Try next path
|
||||
continue; |
||||
} |
||||
} |
||||
|
||||
if (!changelogContent) { |
||||
throw new Error('changelog.yaml not found in any expected location'); |
||||
} |
||||
|
||||
return new Response(changelogContent, { |
||||
headers: { |
||||
'Content-Type': 'application/x-yaml', |
||||
'Cache-Control': 'public, max-age=3600' // Cache for 1 hour
|
||||
} |
||||
}); |
||||
} catch (error) { |
||||
console.error('Failed to read changelog.yaml:', error); |
||||
// Return empty changelog on error
|
||||
const emptyChangelog = 'versions:\n'; |
||||
return new Response(emptyChangelog, { |
||||
status: 404, |
||||
headers: { |
||||
'Content-Type': 'application/x-yaml' |
||||
} |
||||
}); |
||||
} |
||||
}; |
||||
Loading…
Reference in new issue