docs: add missing OpenAPI annotations for signup/verify, billing/success, billing/webhook
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 16m15s
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 16m15s
This commit is contained in:
parent
427ec8e894
commit
8b31d11e74
15 changed files with 2167 additions and 128 deletions
52
dist/index.js
vendored
52
dist/index.js
vendored
|
|
@ -22,7 +22,7 @@ import { pdfRateLimitMiddleware, getConcurrencyStats } from "./middleware/pdfRat
|
|||
import { initBrowser, closeBrowser } from "./services/browser.js";
|
||||
import { loadKeys, getAllKeys } from "./services/keys.js";
|
||||
import { verifyToken, loadVerifications } from "./services/verification.js";
|
||||
import { initDatabase, pool } from "./services/db.js";
|
||||
import { initDatabase, pool, cleanupStaleData } from "./services/db.js";
|
||||
import { swaggerSpec } from "./swagger.js";
|
||||
const app = express();
|
||||
const PORT = parseInt(process.env.PORT || "3100", 10);
|
||||
|
|
@ -142,6 +142,17 @@ app.get("/v1/usage", authMiddleware, adminAuth, (req, res) => {
|
|||
app.get("/v1/concurrency", authMiddleware, adminAuth, (_req, res) => {
|
||||
res.json(getConcurrencyStats());
|
||||
});
|
||||
// Admin: database cleanup (admin key required)
|
||||
app.post("/admin/cleanup", authMiddleware, adminAuth, async (_req, res) => {
|
||||
try {
|
||||
const results = await cleanupStaleData();
|
||||
res.json({ status: "ok", cleaned: results });
|
||||
}
|
||||
catch (err) {
|
||||
logger.error({ err }, "Admin cleanup failed");
|
||||
res.status(500).json({ error: "Cleanup failed", message: err.message });
|
||||
}
|
||||
});
|
||||
// Email verification endpoint
|
||||
app.get("/verify", (req, res) => {
|
||||
const token = req.query.token;
|
||||
|
|
@ -190,10 +201,12 @@ p{color:#7a8194;margin-bottom:24px;line-height:1.6}
|
|||
<p>${message}</p>
|
||||
${apiKey ? `
|
||||
<div class="warning">⚠️ Save your API key securely. You can recover it via email if needed.</div>
|
||||
<div class="key-box" onclick="navigator.clipboard.writeText('${apiKey}');this.style.borderColor='#5eead4';setTimeout(()=>this.style.borderColor='#34d399',1500)">${apiKey}</div>
|
||||
<div class="key-box" data-copy="${apiKey}">${apiKey}</div>
|
||||
<div class="links">Upgrade to Pro for 5,000 PDFs/month · <a href="/docs">Read the docs →</a></div>
|
||||
` : `<div class="links"><a href="/">← Back to DocFast</a></div>`}
|
||||
</div></body></html>`;
|
||||
</div>
|
||||
<script src="/copy-helper.js"></script>
|
||||
</body></html>`;
|
||||
}
|
||||
// Landing page
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
|
@ -222,6 +235,11 @@ app.use((req, res, next) => {
|
|||
}
|
||||
next();
|
||||
});
|
||||
// Landing page (explicit route to set Cache-Control header)
|
||||
app.get("/", (_req, res) => {
|
||||
res.setHeader('Cache-Control', 'public, max-age=3600');
|
||||
res.sendFile(path.join(__dirname, "../public/index.html"));
|
||||
});
|
||||
app.use(express.static(path.join(__dirname, "../public"), {
|
||||
etag: true,
|
||||
cacheControl: false,
|
||||
|
|
@ -316,6 +334,16 @@ async function start() {
|
|||
await initBrowser();
|
||||
logger.info(`Loaded ${getAllKeys().length} API keys`);
|
||||
const server = app.listen(PORT, () => logger.info(`DocFast API running on :${PORT}`));
|
||||
// Run database cleanup 30 seconds after startup (non-blocking)
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
logger.info("Running scheduled database cleanup...");
|
||||
await cleanupStaleData();
|
||||
}
|
||||
catch (err) {
|
||||
logger.error({ err }, "Startup cleanup failed (non-fatal)");
|
||||
}
|
||||
}, 30_000);
|
||||
let shuttingDown = false;
|
||||
const shutdown = async (signal) => {
|
||||
if (shuttingDown)
|
||||
|
|
@ -355,9 +383,19 @@ async function start() {
|
|||
};
|
||||
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
||||
process.on("SIGINT", () => shutdown("SIGINT"));
|
||||
process.on("uncaughtException", (err) => {
|
||||
logger.fatal({ err }, "Uncaught exception — shutting down");
|
||||
process.exit(1);
|
||||
});
|
||||
process.on("unhandledRejection", (reason) => {
|
||||
logger.fatal({ err: reason }, "Unhandled rejection — shutting down");
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
if (process.env.NODE_ENV !== "test") {
|
||||
start().catch((err) => {
|
||||
logger.error({ err }, "Failed to start");
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
start().catch((err) => {
|
||||
logger.error({ err }, "Failed to start");
|
||||
process.exit(1);
|
||||
});
|
||||
export { app };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue