25 lines
763 B
JavaScript
25 lines
763 B
JavaScript
|
'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');
|
||
|
db.get('select webfinger from accounts where name = $name', {$name: name}, (err, result) => {
|
||
|
if (result === undefined) {
|
||
|
return res.status(404).send(`No record found for ${name}.`);
|
||
|
}
|
||
|
else {
|
||
|
res.json(JSON.parse(result.webfinger));
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
|
||
|
module.exports = router;
|