possumbot/auth-fetch.js
2024-08-22 15:34:03 +00:00

61 lines
1.3 KiB
JavaScript

import express from "express";
import fs from "fs";
import env from "dotenv";
env.config();
const domain = process.env.AP_FETCH_DOMAIN;
const pubkey = fs.readFileSync("data/publickey.crt", 'utf8');
const app = express();
const notice = `Don't worry, this doesn't scrape your data.`;
const actor = {
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1"
],
"id": "https://" + domain + "/actor",
"type": "Person",
"preferredUsername": "possumbot",
"inbox": "https://" + domain + "/inbox",
"publicKey": {
"id": "https://" + domain + "/actor#main-key",
"owner": "https://" + domain + "/actor",
"publicKeyPem": pubkey
}
}
const webfinger = {
"subject": "acct:possumbot@" + domain + "",
"links": [
{
"rel": "self",
"type": "application/activity+json",
"href": "https://" + domain + "/actor"
}
]
}
app.get("/", (req, res) => {
res.setHeader('content-type', 'text/plain');
res.send(notice);
});
app.get("/actor", (req, res) => {
res.setHeader('content-type', 'application/activity+json');
res.send(JSON.stringify(actor));
});
app.get("/.well-known/webfinger", (req, res) => {
res.setHeader('content-type', 'application/activity+json');
res.send(JSON.stringify(webfinger));
});
app.listen(process.env.AP_FETCH_PORT);
export default true;