const db = knex({
client: 'better-sqlite3',
connection: {
- filename: join(__dirname, '..', 'data.db')
+ filename: join('./data.db')
}
});
const parser = new Parser();
}
app.use(express.static(join(__dirname, 'public')));
+app.use(express.json());
app.use((req, res, next) => {
console.log(`${req.method}: ${req.url}`);
}).join("\n"));
});
+app.post('/feeds', async (req, res) => {
+ if(req.body.key !== process.env.ADMIN_KEY) {
+ res.sendStatus(400).end();
+ return;
+ }
+ const now = new Date();
+ const feed = {
+ url: req.body.url,
+ title: req.body.title,
+ favicon: req.body.favicon,
+ created_at: now,
+ updated_at: now
+ };
+
+ const rows = await db('feeds').insert(feed).onConflict().ignore().returning('*');
+
+ res.json(rows);
+});
+
+app.get('/feeds', async (req, res) => {
+ res.json(await db.select('*').from('feeds').orderBy('created_at'));
+})
+
app.listen(process.env.API_PORT, () => {
console.log(`Listening on port ${process.env.API_PORT}`);
console.log(`Feed refresh rate: ${(Number(process.env.FEED_REFRESH_RATE) + 1)}m`);