|
|
import express from 'express'; |
|
|
import cors from 'cors'; |
|
|
import dotenv from 'dotenv'; |
|
|
import chatRoutes from './routes/chat.js'; |
|
|
|
|
|
|
|
|
dotenv.config(); |
|
|
process.env.MPLCONFIGDIR = './.cache/matplotlib'; |
|
|
|
|
|
const app = express(); |
|
|
const PORT = process.env.PORT || 3050; |
|
|
|
|
|
|
|
|
app.use(cors()); |
|
|
app.use(express.json()); |
|
|
|
|
|
|
|
|
app.use('/api/chat', chatRoutes); |
|
|
|
|
|
|
|
|
app.get('/api/chat/ping', (req, res) => { |
|
|
res.status(200).send('Chat service active'); |
|
|
}); |
|
|
|
|
|
|
|
|
app.use((err, req, res, next) => { |
|
|
if (err.response?.status === 404) { |
|
|
return res.status(404).json({ |
|
|
error: 'Chat endpoint not found', |
|
|
solution: 'Check your API route configuration' |
|
|
}); |
|
|
} |
|
|
next(err); |
|
|
}); |
|
|
|
|
|
app.listen(PORT, () => { |
|
|
console.log(`π Chat API running on port ${PORT}`); |
|
|
console.log(`π OpenAI Key: ${process.env.NOVITA_API_KEY ? 'Loaded' : 'MISSING!'}`); |
|
|
}); |