rubberguppe/routes/webfinger.js

24 lines
733 B
JavaScript
Raw Normal View History

2018-09-15 07:01:19 +00:00
'use strict';
const express = require('express'),
router = express.Router();
router.get('/', function (req, res) {
let resource = req.query.resource;
if (!resource || !resource.includes('acct:')) {
return res.status(400).send('Bad request. Please make sure "acct:USER@DOMAIN" is what you are sending as the "resource" query parameter.');
}
else {
let name = resource.replace('acct:','');
let db = req.app.get('db');
2019-03-26 05:17:24 +00:00
let result = db.prepare('select webfinger from accounts where name = ?').get(name);
if (result === undefined) {
return res.status(404).send(`No record found for ${name}.`);
}
else {
res.json(JSON.parse(result.webfinger));
}
2018-09-15 07:01:19 +00:00
}
});
module.exports = router;