aboutsummaryrefslogtreecommitdiffstats
path: root/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'index.ts')
-rw-r--r--index.ts77
1 files changed, 51 insertions, 26 deletions
diff --git a/index.ts b/index.ts
index a401d3d3..17f776ec 100644
--- a/index.ts
+++ b/index.ts
@@ -1,7 +1,8 @@
import app from "$lib/app";
-import { admin, auth, optional } from "$lib/auth";
+import { auth, optional } from "$lib/auth";
-import { fixBolt12, listenForLightning, replay } from "$lib/lightning";
+import { fixBolt12, listenForLightning, ensureListenerAlive, replay } from "$lib/lightning";
+import { startHealthCheck } from "$lib/health";
import { getLocations } from "$lib/locations";
import nwc from "$lib/nwc";
import { catchUp, check } from "$lib/payments";
@@ -17,8 +18,10 @@ import lnurl from "$routes/lnurl";
import locations from "$routes/locations";
import nostr from "$routes/nostr";
import payments from "$routes/payments";
+import preimages from "$routes/preimages";
import rates from "$routes/rates";
import shopify from "$routes/shopify";
+import square from "$routes/square";
import users from "$routes/users";
try {
@@ -27,14 +30,15 @@ try {
catchUp();
nwc();
check();
-} catch (e) {
- console.log(e);
-}
+ startHealthCheck();
+} catch (e) {}
setTimeout(listenForLightning, 2000);
-setInterval(sendHeartbeat, 2000);
+setInterval(ensureListenerAlive, 120000);
+setInterval(sendHeartbeat, 5000);
app.get("/balances", info.balances);
+app.get("/health", info.health);
app.post("/email", email.send);
app.get("/fx", rates.fx);
@@ -43,11 +47,16 @@ app.get("/rates", rates.index);
app.get("/locations", locations.list);
-app.get("/invoice/:id", invoices.get);
+app.get("/invoice/:id", { config: { rateLimit: { max: 30, timeWindow: 10000, keyGenerator: (req) => { const ip = (req.headers["cf-connecting-ip"] as string) || req.ip; const token = (req.headers.authorization || "").slice(0, 50); return token ? `invoice:${token}` : `invoice:${ip}`; } } } }, invoices.get);
app.get("/invoices", auth, invoices.list);
-app.post("/invoice", optional, invoices.create);
+app.post("/invoice", { ...optional, config: { rateLimit: { max: 30, timeWindow: 10000, keyGenerator: (req) => `invoicecreate:${(req.headers["cf-connecting-ip"] as string) || req.ip}` } } }, invoices.create);
+app.post("/invoice/:id", { ...optional, config: { rateLimit: { max: 30, timeWindow: 10000, keyGenerator: (req) => `invoiceupdate:${(req.headers["cf-connecting-ip"] as string) || req.ip}` } } }, invoices.update);
app.post("/sign", auth, invoices.sign);
+app.get("/preimages", auth, preimages.list);
+app.post("/preimages", auth, preimages.add);
+app.post("/preimages/delete", auth, preimages.clear);
+
app.get("/assetlinks.json", (_, res) => res.sendFile("assetlinks.json"));
app.get("/nostr.json", nostr.identities);
app.get("/profile/:profile", nostr.profile);
@@ -65,29 +74,52 @@ app.post("/zapRequest", auth, nostr.zapRequest);
app.get("/thread/:id", nostr.thread);
app.get("/info", payments.info);
+app.post("/sendinvoice", auth, payments.sendinvoice);
app.post("/payments", auth, payments.create);
app.get("/payments", auth, payments.list);
app.get("/payments/:hash", payments.get);
app.post("/parse", auth, payments.parse);
-app.get("/fund/:name", payments.fund);
+app.get("/fund/:id", optional, payments.fund);
// app.get("/fund/:name/withdraw", auth, payments.withdraw);
app.get("/fund/:name/managers", payments.managers);
app.post("/fund/managers", auth, payments.addManager);
+app.post("/fund/:name/managers/delete", auth, payments.deleteManager);
+app.post("/authorize", auth, payments.authorize);
app.post("/take", auth, payments.take);
app.post("/print", auth, payments.print);
app.post("/send/:lnaddress/:amount", auth, payments.lnaddress);
app.post("/send", auth, payments.internal);
-app.post("/gateway", payments.gateway);
app.post("/replace", auth, payments.replace);
app.get("/decode/:bolt11", payments.decode);
+app.post(
+ "/lightning/quote",
+ {
+ ...auth,
+ config: {
+ rateLimit: {
+ max: 20,
+ timeWindow: 10000,
+ keyGenerator: (req) => `lnquote:${(req.headers.authorization || "").slice(0, 50) || (req.headers["cf-connecting-ip"] as string) || req.ip}`,
+ },
+ },
+ },
+ payments.quote,
+);
+app.get("/offer", auth, payments.offer);
app.post("/fetchinvoice", payments.fetchinvoice);
+app.get("/square/connect", auth, square.connect);
+app.get("/square/auth", auth, square.auth);
+app.post("/square/payment", square.payment);
+
app.get("/encode", lnurl.encode);
app.get("/decode", lnurl.decode);
+app.get("/lnurl/proxy", lnurl.proxy);
app.get("/lnurl/verify/:id", lnurl.verify);
app.get("/lnurlp/:username", lnurl.lnurlp);
app.get("/lnurl/:id", lnurl.lnurl);
app.get("/pay/:username", lnurl.pay);
+app.get("/pay/:username/:amount", lnurl.pay);
// app.get("/lnurlw", lnurl.withdraw);
app.post("/freeze", payments.freeze);
@@ -102,16 +134,17 @@ app.get("/accounts", auth, users.accounts);
app.post("/accounts", auth, users.createAccount);
app.post("/account/delete", auth, users.deleteAccount);
-app.get("/users", auth, users.list);
app.get("/me", auth, users.me);
+app.get("/ro", auth, users.ro);
app.get("/credits", auth, users.credits);
app.get("/users/:key", users.get);
app.post("/register", users.create);
app.post("/disable2fa", auth, users.disable2fa);
app.post("/2fa", auth, users.enable2fa);
app.post("/user", auth, users.update);
+app.post("/delete", auth, users.deleteSelf);
app.post("/reset", optional, users.reset);
-app.post("/upload/:type", users.upload);
+app.post("/upload/:type", auth, users.upload);
app.get("/users/delete/:username", users.del);
app.post("/acl", users.acl);
app.post("/superuser", users.superuser);
@@ -131,7 +164,7 @@ app.post(
},
users.login,
);
-app.post("/printer", users.printer);
+app.post("/flash", users.flash);
app.get("/challenge", users.challenge);
app.post("/nostrAuth", users.nostrAuth);
app.get("/app/:pubkey", auth, users.app);
@@ -150,6 +183,7 @@ app.get("/subscriptions", auth, users.subscriptions);
app.post("/subscription", auth, users.subscription);
app.post("/subscription/delete", auth, users.deleteSubscription);
app.post("/password", auth, users.password);
+app.post("/nsec", auth, users.nsec);
app.post("/pin", auth, users.pin);
app.post("/otpsecret", auth, users.otpsecret);
app.get("/contacts/:limit?", auth, users.contacts);
@@ -162,32 +196,23 @@ app.post("/items/sort", auth, items.sort);
app.post("/shopify/:id", shopify);
-app.post("/hidepay", admin, users.hidepay);
-app.post("/unlimit", admin, users.unlimit);
app.get("/bolt12", fixBolt12);
app.get("/cash/:id/:version", ecash.get);
-app.post("/cash", ecash.save);
+app.post("/ecash/status", ecash.status);
app.post("/claim", auth, ecash.claim);
-app.post("/mint", auth, ecash.mint);
-app.post("/melt", auth, ecash.melt);
app.post("/ecash/:id", ecash.receive);
app.get("/replay/:index", (req, res) => {
- replay(req.params.index);
+ // replay(req.params.index);
res.send({});
});
-app.post("/echo", (req, res) => {
- console.log("echo", req.body);
- res.send(req.body);
-});
-
const host: string = process.env["HOST"] || "0.0.0.0";
-const port: number = parseInt(process.env["PORT"]) || 3119;
+const port: number = Number.parseInt(process.env["PORT"]) || 3119;
app.listen({ host, port });
-const logerr = (e: Error) => console.log(e);
+const logerr = (e: Error) => {};
process.on("unhandledRejection", logerr);
process.on("uncaughtException", logerr);