feat: separate-routes
This commit is contained in:
63
server.js
63
server.js
@@ -43,6 +43,26 @@ const wss = new WebSocketServer({ server });
|
||||
app.use(express.json());
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
app.get('/tasks', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'public', 'tasks.html'));
|
||||
});
|
||||
|
||||
app.get('/wiki', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'public', 'wiki.html'));
|
||||
});
|
||||
|
||||
app.get('/agents', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'public', 'agents.html'));
|
||||
});
|
||||
|
||||
app.get('/usage', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'public', 'usage.html'));
|
||||
});
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.redirect('/tasks');
|
||||
});
|
||||
|
||||
function normalizeTask(row) {
|
||||
return {
|
||||
...row,
|
||||
@@ -122,6 +142,49 @@ app.get('/api/tasks', (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/api/wiki', (req, res) => {
|
||||
try {
|
||||
const files = [];
|
||||
|
||||
if (fs.existsSync(WIKI_DIR)) {
|
||||
const wikiFiles = fs.readdirSync(WIKI_DIR).filter(f => f.endsWith('.md'));
|
||||
|
||||
wikiFiles.forEach(filename => {
|
||||
const filePath = path.join(WIKI_DIR, filename);
|
||||
const stats = fs.statSync(filePath);
|
||||
files.push({
|
||||
filename,
|
||||
created: stats.mtime.toISOString()
|
||||
});
|
||||
});
|
||||
|
||||
files.sort((a, b) => new Date(b.created) - new Date(a.created));
|
||||
}
|
||||
|
||||
res.json(files);
|
||||
} catch (err) {
|
||||
console.error('Error reading wiki:', err);
|
||||
res.status(500).json({ error: 'failed_to_fetch_wiki' });
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/api/wiki/:filename', (req, res) => {
|
||||
try {
|
||||
const filename = req.params.filename;
|
||||
const filePath = path.join(WIKI_DIR, filename);
|
||||
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return res.status(404).json({ error: 'wiki_page_not_found' });
|
||||
}
|
||||
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
res.json({ content });
|
||||
} catch (err) {
|
||||
console.error('Error reading wiki page:', err);
|
||||
res.status(500).json({ error: 'failed_to_fetch_wiki_page' });
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/tasks', (req, res) => {
|
||||
const errors = validatePayload(req.body, false);
|
||||
if (errors.length) {
|
||||
|
||||
Reference in New Issue
Block a user