the-forest/server/routes/api.js

38 lines
875 B
JavaScript
Raw Normal View History

const { graphFromList } = require('../graphStuff.js');
const sqlite = require('better-sqlite3');
const db = new sqlite('the_big_db.db', { verbose: console.log });
const express = require('express');
const app = express.Router();
const page_routes = require('./pages.js');
app.use(page_routes);
const user_routes = require('./users.js');
app.use(user_routes);
const live_connection_routes = require('./live.js');
app.use(live_connection_routes);
2024-10-06 16:01:13 -04:00
const graphQuery = db.prepare(`
select p.number, p.html, p.time
from pages p
where time >= (
select max(s.time)
from pages s
where s.number = p.number
)
order by p.time desc
`);
app.get('/graph', (req, res) => {
try {
2024-10-06 16:01:13 -04:00
const rows = graphQuery.all();
const graph = graphFromList(rows);
res.status(200).json(graph);
} catch (error) {
res.status(500).json({"error": error});
}
});
module.exports = app;