Add version updater feature
Added a version updater component that frequently checks for updates to the app and alerts the user if necessary. This requires a new route, config changes, and additional UI resources. A new feature flag 'enableVersionUpdater' has been added in the feature-flags.config.ts file to toggle this feature.
This commit is contained in:
38
apps/web/app/version/route.ts
Normal file
38
apps/web/app/version/route.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* We force it to static because we want to cache for as long as the build is live.
|
||||
*/
|
||||
export const dynamic = 'force-static';
|
||||
|
||||
// please provide your own implementation
|
||||
// if you're not using Vercel or Cloudflare Pages
|
||||
const KNOWN_GIT_ENV_VARS = [
|
||||
'CF_PAGES_COMMIT_SHA',
|
||||
'VERCEL_GIT_COMMIT_SHA',
|
||||
'GIT_HASH',
|
||||
];
|
||||
|
||||
export const GET = async () => {
|
||||
const currentGitHash = await getGitHash();
|
||||
|
||||
return new Response(currentGitHash, {
|
||||
headers: {
|
||||
'content-type': 'text/plain',
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
function getGitHash() {
|
||||
for (const envVar of KNOWN_GIT_ENV_VARS) {
|
||||
if (process.env[envVar]) {
|
||||
return process.env[envVar];
|
||||
}
|
||||
}
|
||||
|
||||
return getHashFromProcess();
|
||||
}
|
||||
|
||||
async function getHashFromProcess() {
|
||||
const { execSync } = await import('child_process');
|
||||
|
||||
return execSync('git log --pretty=format:"%h" -n1').toString().trim();
|
||||
}
|
||||
Reference in New Issue
Block a user