Try adding lnurlp logic into .well-known endpoint directly instead of redirect endpoint

This commit is contained in:
austinkelsay 2024-11-15 13:45:38 -06:00
parent db9f922175
commit 6a8634f2a4
No known key found for this signature in database
GPG Key ID: 44CB4EC6D9F2FA02

View File

@ -1,10 +1,46 @@
import appConfig from "@/config/appConfig"
import { runMiddleware, corsMiddleware } from "@/utils/corsMiddleware";
import { getLightningAddressByName } from "@/db/models/lightningAddressModels";
const BACKEND_URL = process.env.BACKEND_URL
const ZAP_PUBKEY = process.env.ZAP_PUBKEY
export default async function handler(req, res) {
// Run CORS middleware first
await runMiddleware(req, res, corsMiddleware);
// Redirect to your lightning address endpoint
const { slug } = req.query;
res.redirect(307, `/api/lightning-address/lnurlp/${slug}`);
if (!slug || slug === 'undefined') {
res.status(404).json({ error: 'Not found' })
return
}
let foundAddress = null;
const customAddress = appConfig.customLightningAddresses.find(addr => addr.name === slug);
if (customAddress) {
foundAddress = customAddress;
} else {
foundAddress = await getLightningAddressByName(slug);
}
if (!foundAddress) {
res.status(404).json({ error: 'Lightning address not found' })
return
}
const metadata = [
["text/plain", `${foundAddress.description}`]
];
res.status(200).json({
callback: `${BACKEND_URL}/api/lightning-address/callback/${foundAddress.name}`,
maxSendable: foundAddress.maxSendable || 10000000000,
minSendable: foundAddress.minSendable || 1000,
metadata: JSON.stringify(metadata),
tag: 'payRequest',
allowsNostr: true,
nostrPubkey: ZAP_PUBKEY
});
}