@fedify/fedify
Version:
An ActivityPub server framework
50 lines (49 loc) • 1.81 kB
JavaScript
import { RouterError } from "../federation/router.js";
import { nodeInfoToJson } from "./types.js";
/**
* Handles a NodeInfo request. You would not typically call this function
* directly, but instead use {@link Federation.handle} method.
* @param request The NodeInfo request to handle.
* @param parameters The parameters for handling the request.
* @returns The response to the request.
*/
export async function handleNodeInfo(_request, { context, nodeInfoDispatcher }) {
const promise = nodeInfoDispatcher(context);
const nodeInfo = promise instanceof Promise ? await promise : promise;
const json = nodeInfoToJson(nodeInfo);
return new Response(JSON.stringify(json), {
headers: {
"Content-Type": "application/json;" +
' profile="http://nodeinfo.diaspora.software/ns/schema/2.1#"',
},
});
}
/**
* Handles a request to `/.well-known/nodeinfo`. You would not typically call
* this function directly, but instead use {@link Federation.handle} method.
* @param request The request to handle.
* @param context The request context.
* @returns The response to the request.
*/
export function handleNodeInfoJrd(_request, context) {
const links = [];
try {
links.push({
rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
href: context.getNodeInfoUri().href,
type: "application/json;" +
' profile="http://nodeinfo.diaspora.software/ns/schema/2.1#"',
});
}
catch (e) {
if (!(e instanceof RouterError))
throw e;
}
const jrd = { links };
const response = new Response(JSON.stringify(jrd), {
headers: {
"Content-Type": "application/jrd+json",
},
});
return Promise.resolve(response);
}