matrix-public-archive/server/server1.js

42 lines
1.0 KiB
JavaScript
Raw Normal View History

const express = require('express');
2022-02-07 18:55:11 -07:00
const asyncHandler = require('./express-async-handler');
2022-02-07 18:55:11 -07:00
const fetchEventsForTimestamp = require('./fetch-events-for-timestamp');
const renderHydrogenToString = require('./render-hydrogen-to-string');
2022-02-07 18:55:11 -07:00
const app = express();
2022-02-04 00:54:12 -07:00
app.get('/style.css', async function (req, res) {
res.set('Content-Type', 'text/css');
res.sendFile(require.resolve('hydrogen-view-sdk/style.css'));
});
2022-02-07 18:55:11 -07:00
app.get(
'/',
asyncHandler(async function (req, res) {
const { events, stateEventMap } = await fetchEventsForTimestamp(
'!HBehERstyQBxyJDLfR:my.synapse.server',
new Date('2022-02-08').getTime()
2022-02-07 18:55:11 -07:00
);
2022-02-04 00:54:12 -07:00
2022-02-07 18:55:11 -07:00
const hydrogenHtmlOutput = await renderHydrogenToString(events, stateEventMap);
const pageHtml = `
2022-02-04 00:54:12 -07:00
<!doctype html>
<html lang="en">
<head>
<link href="style.css" rel="stylesheet">
</head>
<body>
${hydrogenHtmlOutput}
</body>
</html>
`;
2022-02-07 18:55:11 -07:00
res.set('Content-Type', 'text/html');
res.send(pageHtml);
})
);
app.listen(3050);