**refactor: improve imports, route handling, and environment detection**
### Changes: - Added explicit `.js` extensions to imports in `cloud-wrapper/src/index.ts` for Node.js compatibility. - Refactored `setupRoutes` usage by introducing an `apiRouter` variable for clarity and consistency in middleware. - Simplified environment detection in `src/unified.ts` by delegating it to build-time logic: - Removed inline environment detection (`isBrowser`, `isNode`, `isServerless`). - Updated `environment` export with build-generated properties. ### Purpose: Enhanced compatibility with Node.js module resolution, improved code clarity in route handling, and streamlined environment detection by consolidating it into the build process. These changes reduce redundancy, improve maintainability, and align with modern JavaScript practices.
This commit is contained in:
parent
ced7c6eaec
commit
0cf4a0eee8
2 changed files with 11 additions and 15 deletions
|
|
@ -6,9 +6,9 @@ import dotenv from 'dotenv';
|
|||
import http from 'http';
|
||||
import { WebSocketServer } from 'ws';
|
||||
import { BrainyData } from '@soulcraft/brainy';
|
||||
import { setupRoutes } from './routes';
|
||||
import { initializeBrainy } from './services/brainyService';
|
||||
import { setupWebSocketHandlers } from './websocket';
|
||||
import { setupRoutes } from './routes.js';
|
||||
import { initializeBrainy } from './services/brainyService.js';
|
||||
import { setupWebSocketHandlers } from './websocket.js';
|
||||
|
||||
// Load environment variables
|
||||
dotenv.config();
|
||||
|
|
@ -32,11 +32,12 @@ app.get('/health', (req, res) => {
|
|||
});
|
||||
|
||||
// Setup API routes
|
||||
const apiRouter = setupRoutes();
|
||||
app.use('/api', (req, res, next) => {
|
||||
// Attach brainy instance to request
|
||||
(req as any).brainy = brainyInstance;
|
||||
next();
|
||||
}, setupRoutes());
|
||||
}, apiRouter);
|
||||
|
||||
// Start the server
|
||||
async function startServer() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue