81 lines
2.6 KiB
TypeScript
81 lines
2.6 KiB
TypeScript
import Fastify from 'fastify';
|
|
import cors from '@fastify/cors';
|
|
import { config } from './config/index.js';
|
|
import { ZfsService } from './services/zfs.service.js';
|
|
import { GitOpsService } from './services/gitops.service.js';
|
|
import { RebuildService } from './services/rebuild.service.js';
|
|
import { AppsService } from './services/apps.service.js';
|
|
import { SharesService } from './services/shares.service.js';
|
|
import { UsersService } from './services/users.service.js';
|
|
import { LogsService } from './services/logs.service.js';
|
|
import { PersesService } from './services/perses.service.js';
|
|
|
|
import { registerStorageRoutes } from './routes/storage.routes.js';
|
|
import { registerGitOpsRoutes } from './routes/gitops.routes.js';
|
|
import { registerAppsRoutes } from './routes/apps.routes.js';
|
|
import { registerSharesRoutes } from './routes/shares.routes.js';
|
|
import { registerUsersRoutes } from './routes/users.routes.js';
|
|
import { registerLogsRoutes } from './routes/logs.routes.js';
|
|
import { registerSystemRoutes } from './routes/system.routes.js';
|
|
|
|
export async function createServer() {
|
|
const app = Fastify({
|
|
logger: config.isDev
|
|
? {
|
|
transport: {
|
|
target: 'pino-pretty',
|
|
options: { colorize: true },
|
|
},
|
|
}
|
|
: true,
|
|
});
|
|
|
|
await app.register(cors, {
|
|
origin: true,
|
|
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
|
|
});
|
|
|
|
// Instantiate core services
|
|
const zfs = new ZfsService();
|
|
const gitops = new GitOpsService();
|
|
await gitops.init();
|
|
|
|
const rebuild = new RebuildService();
|
|
const apps = new AppsService(gitops);
|
|
const shares = new SharesService(gitops);
|
|
const users = new UsersService(gitops);
|
|
const logs = new LogsService();
|
|
const perses = new PersesService(zfs, gitops);
|
|
|
|
// Health check
|
|
app.get('/health', async () => {
|
|
return { status: 'healthy', version: '1.0.0', uptime: process.uptime() };
|
|
});
|
|
|
|
// Register routes
|
|
registerStorageRoutes(app, zfs);
|
|
registerGitOpsRoutes(app, gitops);
|
|
registerAppsRoutes(app, apps);
|
|
registerSharesRoutes(app, shares);
|
|
registerUsersRoutes(app, users);
|
|
registerLogsRoutes(app, logs);
|
|
registerSystemRoutes(app, perses, rebuild);
|
|
|
|
return app;
|
|
}
|
|
|
|
async function start() {
|
|
try {
|
|
const app = await createServer();
|
|
await app.listen({ port: config.port, host: config.host });
|
|
console.log(`NaxOS Management Daemon running on http://${config.host}:${config.port}`);
|
|
} catch (err) {
|
|
console.error('Fatal error starting NaxOS Management Daemon:', err);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
if (process.argv[1] && process.argv[1].endsWith('server.js')) {
|
|
start();
|
|
}
|