test_logic_backend / server.js
lljz66's picture
Upload server.js
ced6a3b verified
Raw
History Blame Contribute Delete
1.04 kB
const express = require('express');
const cors = require('cors');
const path = require('path');
const fs = require('fs');
const app = express();
app.use(cors());
app.use(express.static(path.join(__dirname, 'public')));
// Tool registry
const tools = [
{ id: 'trending', name: 'Trending Apps', path: '/api/trending', file: 'trending.js' },
{ id: 'search', name: 'Search Apps', path: '/api/search', file: 'search.js' }
];
// Load tools dynamically
const toolsDir = path.join(__dirname, 'tools');
tools.forEach(tool => {
const toolPath = path.join(toolsDir, tool.file);
if (fs.existsSync(toolPath)) {
require(toolPath)(app);
console.log(`Loaded tool: ${tool.name}`);
}
});
app.get('/api/tools', (req, res) => {
res.json({ tools: tools.map(t => ({ id: t.id, name: t.name, path: t.path })) });
});
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
const PORT = process.env.PORT || 7860;
app.listen(PORT, '0.0.0.0', () => {
console.log(`Server running on port ${PORT}`);
});