landvex: Fixar och tester klara för alla komponenter
- Datafabrik: Dockerfile fix, agentorkestrering fungerar - Vision: Identify-modell, FAISS, OCR alla testade - API: Alla 7 integrationstester passerade - Upplösare: Entitetsupplösning verifierad
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* LandveX Intelligence Lab API
|
||||
*
|
||||
* Updated with API Key Management module.
|
||||
*/
|
||||
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
import helmet from 'helmet';
|
||||
|
||||
import missionImportRoutes from './routes/mission-import';
|
||||
import versionRoutes from './routes/version';
|
||||
import { createApiKeyRoutes } from './routes/api-keys';
|
||||
import { ApiKeyService } from './services/api-key-service';
|
||||
import { apiKeyAuth } from './middleware/api-key-auth';
|
||||
import {
|
||||
PostgresApiKeyRepository,
|
||||
PostgresApiKeyUsageRepository,
|
||||
PostgresApiKeyConfig,
|
||||
} from '../../infrastructure/src/adapters/postgresql/postgres-api-key-repository';
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
// PostgreSQL config from environment
|
||||
const pgConfig: PostgresApiKeyConfig = {
|
||||
host: process.env.PG_HOST || 'localhost',
|
||||
port: parseInt(process.env.PG_PORT || '5432', 10),
|
||||
database: process.env.PG_DATABASE || 'landvex',
|
||||
user: process.env.PG_USER || 'landvex',
|
||||
password: process.env.PG_PASSWORD || '',
|
||||
ssl: process.env.PG_SSL === 'true' ? true : undefined,
|
||||
};
|
||||
|
||||
// Initialize repositories and services
|
||||
const apiKeyRepo = new PostgresApiKeyRepository(pgConfig);
|
||||
const usageRepo = new PostgresApiKeyUsageRepository(pgConfig);
|
||||
const apiKeyService = new ApiKeyService(apiKeyRepo, usageRepo);
|
||||
|
||||
// Initialize database tables (in production, use migrations instead)
|
||||
async function initDatabase(): Promise<void> {
|
||||
await apiKeyRepo.init();
|
||||
await usageRepo.init();
|
||||
}
|
||||
|
||||
// Middleware
|
||||
app.use(helmet());
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
// API Key authentication for protected routes
|
||||
// Excludes health check, version, and admin API key management endpoints
|
||||
app.use(apiKeyAuth({
|
||||
service: apiKeyService,
|
||||
excludePaths: ['/health', '/version', '/api-keys'],
|
||||
}));
|
||||
|
||||
// Routes
|
||||
app.use('/api/v1/missions', missionImportRoutes);
|
||||
app.use('/version', versionRoutes);
|
||||
app.use('/api-keys', createApiKeyRoutes(apiKeyService));
|
||||
|
||||
// Health check
|
||||
app.get('/health', (_req, res) => {
|
||||
res.json({ status: 'ok', version: '0.2.0-apikeys' });
|
||||
});
|
||||
|
||||
// Start server
|
||||
async function start() {
|
||||
await initDatabase();
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`🚀 LandveX API running on port ${PORT}`);
|
||||
console.log(`📹 Mission Import: POST /api/v1/missions/import`);
|
||||
console.log(`🔑 API Key Mgmt: POST /api-keys`);
|
||||
console.log(`🏥 Health Check: GET /health`);
|
||||
});
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
start().catch(err => {
|
||||
console.error('Failed to start server:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
export default app;
|
||||
Reference in New Issue
Block a user