File size: 1,119 Bytes
ce30646
cdc50ff
 
 
 
 
ce30646
cdc50ff
 
 
 
7ecba03
 
 
 
cdc50ff
 
 
 
 
 
 
 
 
 
 
ce30646
 
 
 
 
 
cdc50ff
 
 
 
ce30646
cdc50ff
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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 );
} );