possumbot/auth-fetch.js
2024-08-27 20:04:57 +00:00

64 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 = fs.readFileSync('auth-fetch-notice.txt', 'utf8');
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.write(notice);
res.end();
});
app.get('/actor', (req, res) => {
res.writeHead(200, { 'Content-Type': 'application/activity+json' });
res.write(JSON.stringify(actor));
res.end();
});
app.get('/.well-known/webfinger', (req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.write(JSON.stringify(webfinger));
res.end();
});
app.listen(process.env.AP_FETCH_PORT);
export default true;