Spaces:
Sleeping
Sleeping
| import 'dotenv/config'; | |
| import express from 'express'; | |
| import cors from 'cors'; | |
| import articleRoutes from './routes/article.js'; | |
| import searchRoutes from './routes/search.js'; | |
| import { initEmbedder } from './services/embedder.js'; | |
| import { isClaudeAvailable } from './services/claudeQuestionGenerator.js'; | |
| const app = express(); | |
| const PORT = process.env.PORT || 3000; | |
| app.use( cors( { | |
| origin: true, | |
| credentials: true | |
| } ) ); | |
| app.use( express.json() ); | |
| // Routes | |
| app.use( '/api/article', articleRoutes ); | |
| app.use( '/api/search', searchRoutes ); | |
| // Health check | |
| app.get( '/api/health', ( _, res ) => { | |
| res.json( { status: 'ok' } ); | |
| } ); | |
| // Pre-warm the embedding model on startup | |
| console.log( 'Starting server and loading embedding model...' ); | |
| initEmbedder().then( () => { | |
| if ( !isClaudeAvailable() ) { | |
| console.warn( 'Warning: ANTHROPIC_API_KEY not set. Question generation will be disabled.' ); | |
| } | |
| app.listen( PORT, () => { | |
| console.log( `Server running on http://localhost:${ PORT }` ); | |
| } ); | |
| } ).catch( ( err ) => { | |
| console.error( 'Failed to initialize embedding model:', err ); | |
| process.exit( 1 ); | |
| } ); | |