- Added @elysiajs/swagger dependency to package.json for API documentation. - Removed the old bed router and replaced it with a new history router. - Created a new state router to manage WebSocket connections and state updates. - Implemented a comprehensive state management system with the StateManager service. - Introduced AlarmManagement and BedService services for handling alarms and sensor readings. - Established a new MQTT service for managing MQTT connections and subscriptions. - Created an AlarmStateStore to manage volatile alerts and their states. - Defined FrontendState types for structured state management and WebSocket messaging.
44 lines
No EOL
1 KiB
TypeScript
44 lines
No EOL
1 KiB
TypeScript
import { Elysia } from 'elysia';
|
|
import { cors } from '@elysiajs/cors';
|
|
|
|
import { createTopicLogger } from '~/utils/logger';
|
|
import env from './config/env';
|
|
import stateRouter from './routes/state';
|
|
import swaggerElysia from './routes/swagger';
|
|
|
|
async function initialize() {
|
|
const logger = createTopicLogger({ topic: 'Initializer' });
|
|
try {
|
|
await initializeElysia();
|
|
} catch (error) {
|
|
logger.error(`Initialization error: ${error}`);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
async function initializeElysia() {
|
|
const logger = createTopicLogger({ topic: 'Elysia' });
|
|
const PORT = env.BACKEND_PORT;
|
|
|
|
// Instantiate and configure Elysia
|
|
const app = new Elysia()
|
|
// Logging Messages
|
|
.onStart(() => {
|
|
logger.info(`API server starting on port ${PORT}`);
|
|
})
|
|
.onStop(() => {
|
|
logger.info('API server shutting down');
|
|
})
|
|
|
|
// Core Components
|
|
.use(cors())
|
|
.use(swaggerElysia)
|
|
|
|
// State routes (includes WebSocket)
|
|
.use(stateRouter)
|
|
|
|
// Start the server
|
|
app.listen(PORT);
|
|
}
|
|
|
|
initialize(); |