mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-05 00:32:03 +00:00
simplify cors middleware remove .well-knwon endpoint and stick with redirect
This commit is contained in:
parent
6a8634f2a4
commit
1d54f3d123
@ -1,46 +0,0 @@
|
||||
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);
|
||||
|
||||
const { slug } = req.query;
|
||||
|
||||
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
|
||||
});
|
||||
}
|
@ -2,23 +2,20 @@ import Cors from 'cors';
|
||||
|
||||
// Initialize the cors middleware
|
||||
export const corsMiddleware = Cors({
|
||||
methods: ['GET', 'HEAD', 'POST', 'OPTIONS'],
|
||||
origin: '*',
|
||||
credentials: true,
|
||||
optionsSuccessStatus: 200,
|
||||
allowedHeaders: ['Content-Type', 'Authorization'],
|
||||
methods: ['GET', 'HEAD', 'POST', 'OPTIONS'],
|
||||
origin: '*',
|
||||
});
|
||||
|
||||
|
||||
// Helper method to wait for a middleware to execute before continuing
|
||||
// And to throw an error when an error happens in a middleware
|
||||
export async function runMiddleware(req, res, middleware) {
|
||||
return new Promise((resolve, reject) => {
|
||||
middleware(req, res, (result) => {
|
||||
if (result instanceof Error) {
|
||||
return reject(result);
|
||||
}
|
||||
return resolve(result);
|
||||
});
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
middleware(req, res, (result) => {
|
||||
if (result instanceof Error) {
|
||||
return reject(result);
|
||||
}
|
||||
return resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user