railyard/apps/rithub-billing/ecosystem.config.cjs
caelum0x d6dcc769ee feat(rithub): RIT-MON link Pro payments to accounts, mail customer + owner; billing source into git
rithub-billing recorded who paid but told nobody and never linked a payment
to a Rithub login. The lifecycle timer now runs a Pro pass: email -> login
link, one 'rithub pro is on' mail to the customer, an owner mail on every
status change, and pro-users.json as the one list later Pro limits read.
Tested on railyard-box with a fake entitlement and mail.tm inboxes:
mails delivered, second run sends nothing, revoke mails the owner only.
rithub-billing source copied in from the box (it only lived there).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 17:28:13 +03:00

44 lines
1.4 KiB
JavaScript

// pm2 process definition for the Rithub billing service (RIT-MON: checkout
// + Dodo webhook for the self-serve Rithub Pro plan). Bound to 127.0.0.1
// only -- public exposure is via Caddy's /billing* handle block on
// rithub.dev (see /etc/caddy/sites-enabled/rithub-dev.caddy), same pattern
// already used for rithub-mcp's /mcp*, /agent-tokens*, /agent-signup*.
const fs = require("node:fs");
// Minimal, dependency-free KEY=VALUE loader -- same /etc/products/*.env
// convention used by rithub-mcp (see its ecosystem.config.cjs) and other
// services on this box, read at pm2 start/reload time.
function loadEnvFile(path) {
try {
const out = {};
for (const line of fs.readFileSync(path, "utf8").split("\n")) {
const match = /^([A-Z0-9_]+)=(.*)$/.exec(line.trim());
if (match) out[match[1]] = match[2];
}
return out;
} catch {
return {}; // file not present (e.g. local dev) -- billing stays disabled, /billing/health reports configured:false.
}
}
const secrets = loadEnvFile("/etc/products/rithub-billing.env");
module.exports = {
apps: [
{
name: "rithub-billing",
cwd: __dirname,
script: "bin/start.mjs",
env: {
NODE_ENV: "production",
PORT: "3353",
RITHUB_BILLING_PUBLIC_BASE: "https://rithub.dev",
...secrets,
},
autorestart: true,
max_restarts: 10,
min_uptime: "10s",
},
],
};