This is a new mostly bash-based implementation of a minimal and immanent AO server. No database, user accounts are created directly in the OS.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

72 lines
1.8 KiB

const express = require('express');
const router = express.Router();
const { exec } = require('child_process');
let dir = process.argv[2] || '.';
router.get('/', (req, res) => {
res.send('Welcome to our minimalist web application!')
});
router.get('/api/posts', (req, res) => {
let page = req.query.page || 1;
let limit = req.query.limit || 10;
exec(`./routes/listPosts ${dir} ${page} ${limit}`, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
let posts = stdout.split('\n').filter(Boolean);
res.json(posts);
});
});
router.get('/posts', (req, res) => {
let page = req.query.page || 1;
let limit = req.query.limit || 10;
exec(`./routes/listPosts ${dir} ${page} ${limit}`, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
let posts = stdout.split('\n').filter(Boolean);
let html = '<h1>Posts List</h1><ul>';
posts.forEach(post => {
html += `<li><a href="/viewPost?filename=${post}">${post.replace('.yaml', '')}</a></li>`;
});
html += '</ul>';
res.send(html);
});
});
router.get('/viewPost', (req, res) => {
let { filename } = req.query;
exec(`./routes/viewPost --filename=${filename}`, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
res.send(stdout.split('\n').filter(Boolean));
});
});
/*app.listen(3000, () => {
console.log('Server is running on port 3000');
});
*/
module.exports = router