Spaces:
Running
Running
const express = require('express'); | |
const cors = require('cors'); | |
const path = require('path'); | |
require('dotenv').config(); | |
const app = express(); | |
const PORT = process.env.PORT || 3001; | |
app.use(cors()); | |
app.use(express.json()); | |
const algorithmsRoute = require('./routes/algorithms'); | |
const pubmedRoute = require('./routes/pubmed'); | |
const searchRoute = require('./routes/search'); | |
app.use('/api/algorithms', algorithmsRoute); | |
app.use('/api/pubmed', pubmedRoute); | |
app.use('/api/search', searchRoute); | |
app.get('/api/health', (req, res) => { | |
res.json({ status: 'OK', message: 'PubMed AI Explorer API is running' }); | |
}); | |
// Serve static files from the React app build directory | |
app.use(express.static(path.join(__dirname, '../frontend/dist'))); | |
// Catch all handler: send back React's index.html file for any non-API routes | |
app.get('*', (req, res) => { | |
res.sendFile(path.join(__dirname, '../frontend/dist/index.html')); | |
}); | |
app.listen(PORT, () => { | |
console.log(`Server running on port ${PORT}`); | |
}); |