forked from shadowfacts/shadowfacts.net
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import { Page } from "./metadata";
|
|
import generators from "./generate";
|
|
|
|
import express from "express";
|
|
import morgan from "morgan";
|
|
import bodyParser from "body-parser";
|
|
import activitypub from "./activitypub";
|
|
|
|
import sqlite3 from "sqlite3";
|
|
|
|
const db = new (sqlite3.verbose().Database)(process.env.DB_PATH!);
|
|
|
|
db.run("CREATE TABLE IF NOT EXISTS followers (id TEXT PRIMARY KEY, inbox TEXT)");
|
|
db.run("CREATE TABLE IF NOT EXISTS articles (id TEXT PRIMARY KEY, article_doc TEXT, has_federated INT)");
|
|
db.run("CREATE TABLE IF NOT EXISTS notes (id TEXT PRIMARY KEY, content TEXT, attributed_to TEXT, in_reply_to TEXT, published TEXT)");
|
|
|
|
async function generate(): Promise<Page[]> {
|
|
generators.copy();
|
|
generators.css();
|
|
generators.missing();
|
|
|
|
const tutorials = await generators.tutorials();
|
|
|
|
const posts = await generators.posts();
|
|
generators.homepage(posts);
|
|
generators.redirects(posts);
|
|
const categories = await generators.categories(posts);
|
|
await generators.rss(posts, categories, tutorials);
|
|
|
|
return posts;
|
|
}
|
|
|
|
const app = express();
|
|
app.set("db", db);
|
|
app.use(morgan("dev"));
|
|
app.use(bodyParser.json({ type: "application/activity+json" }));
|
|
|
|
//db.run("DELETE FROM articles");
|
|
|
|
(async () => {
|
|
const posts = await generate();
|
|
|
|
await activitypub.articles.setup(posts, db);
|
|
const toFederate = await activitypub.articles.toFederate(db);
|
|
|
|
|
|
app.use(await activitypub.actor());
|
|
app.use(activitypub.followers());
|
|
app.use(activitypub.inbox());
|
|
app.use(activitypub.webfinger());
|
|
app.use(activitypub.articles.router());
|
|
app.use(express.static("out"));
|
|
|
|
const port = process.env.PORT || 8083;
|
|
app.listen(port, () => {
|
|
console.log(`Listening on port ${port}`);
|
|
|
|
activitypub.federate(toFederate, db);
|
|
});
|
|
})();
|
|
|