feat: sync full workspace including web modules, docs, and configurations to Gitea
Optimized the root .gitignore to exclude virtual environments, node modules, and temp folders to ensure clean and lightweight version tracking. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
33
axhub-make/vite-plugins/versionApiPlugin.ts
Normal file
33
axhub-make/vite-plugins/versionApiPlugin.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { Plugin } from 'vite';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { getRequestPathname } from './utils/httpUtils';
|
||||
|
||||
export function versionApiPlugin(): Plugin {
|
||||
return {
|
||||
name: 'version-api-plugin',
|
||||
configureServer(server: any) {
|
||||
server.middlewares.use((req: any, res: any, next: any) => {
|
||||
const pathname = getRequestPathname(req);
|
||||
if (req.method !== 'GET' || pathname !== '/api/version') {
|
||||
return next();
|
||||
}
|
||||
|
||||
try {
|
||||
const pkgPath = path.resolve(process.cwd(), 'package.json');
|
||||
const pkg = fs.existsSync(pkgPath) ? JSON.parse(fs.readFileSync(pkgPath, 'utf8')) : null;
|
||||
const version = pkg?.version ?? null;
|
||||
|
||||
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
||||
res.setHeader('Cache-Control', 'no-store');
|
||||
res.end(JSON.stringify({ version }));
|
||||
} catch (error: any) {
|
||||
res.statusCode = 500;
|
||||
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
||||
res.end(JSON.stringify({ error: error?.message || 'Unknown error' }));
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user