2024-10-25 17:48:12 -04:00
|
|
|
const { graphFromList, graphQueryString } = require('../graphStuff.js');
|
2024-10-04 18:43:08 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2024-10-21 11:56:48 -04:00
|
|
|
const live_connection_routes = require('./live.js');
|
|
|
|
app.use(live_connection_routes);
|
2024-10-08 23:24:48 -04:00
|
|
|
|
2024-10-04 18:43:08 -04:00
|
|
|
app.get('/graph', (req, res) => {
|
|
|
|
try {
|
2024-10-25 17:48:12 -04:00
|
|
|
const rows = db.prepare(graphQueryString).all();
|
|
|
|
const parsedRows = rows.map((row) => {
|
|
|
|
let newRow = row;
|
|
|
|
newRow.contents = JSON.parse(row.contents);
|
|
|
|
return newRow;
|
|
|
|
});
|
|
|
|
const graph = graphFromList(parsedRows);
|
2024-10-04 18:43:08 -04:00
|
|
|
res.status(200).json(graph);
|
|
|
|
} catch (error) {
|
2024-10-25 17:48:12 -04:00
|
|
|
console.log("error:", error);
|
2024-10-04 18:43:08 -04:00
|
|
|
res.status(500).json({"error": error});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = app;
|