DocFast MVP: HTML/Markdown to PDF API with invoice templates
This commit is contained in:
parent
789b3bfeeb
commit
77ec1c5524
24 changed files with 5010 additions and 22 deletions
62
projects/business/src/pdf-api/dist/index.js
vendored
Normal file
62
projects/business/src/pdf-api/dist/index.js
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.app = void 0;
|
||||
const express_1 = __importDefault(require("express"));
|
||||
const helmet_1 = __importDefault(require("helmet"));
|
||||
const express_rate_limit_1 = __importDefault(require("express-rate-limit"));
|
||||
const convert_js_1 = require("./routes/convert.js");
|
||||
const templates_js_1 = require("./routes/templates.js");
|
||||
const health_js_1 = require("./routes/health.js");
|
||||
const auth_js_1 = require("./middleware/auth.js");
|
||||
const browser_js_1 = require("./services/browser.js");
|
||||
const app = (0, express_1.default)();
|
||||
exports.app = app;
|
||||
const PORT = parseInt(process.env.PORT || "3100", 10);
|
||||
app.use((0, helmet_1.default)());
|
||||
app.use(express_1.default.json({ limit: "2mb" }));
|
||||
app.use(express_1.default.text({ limit: "2mb", type: "text/*" }));
|
||||
// Rate limiting: 100 req/min for free tier
|
||||
const limiter = (0, express_rate_limit_1.default)({
|
||||
windowMs: 60_000,
|
||||
max: 100,
|
||||
standardHeaders: true,
|
||||
legacyHeaders: false,
|
||||
});
|
||||
app.use(limiter);
|
||||
// Public
|
||||
app.use("/health", health_js_1.healthRouter);
|
||||
// Authenticated
|
||||
app.use("/v1/convert", auth_js_1.authMiddleware, convert_js_1.convertRouter);
|
||||
app.use("/v1/templates", auth_js_1.authMiddleware, templates_js_1.templatesRouter);
|
||||
// Root
|
||||
app.get("/", (_req, res) => {
|
||||
res.json({
|
||||
name: "DocFast API",
|
||||
version: "0.1.0",
|
||||
docs: "/health",
|
||||
endpoints: [
|
||||
"POST /v1/convert/html",
|
||||
"POST /v1/convert/markdown",
|
||||
"POST /v1/templates/:id/render",
|
||||
"GET /v1/templates",
|
||||
],
|
||||
});
|
||||
});
|
||||
async function start() {
|
||||
await (0, browser_js_1.initBrowser)();
|
||||
app.listen(PORT, () => console.log(`DocFast API running on :${PORT}`));
|
||||
const shutdown = async () => {
|
||||
console.log("Shutting down...");
|
||||
await (0, browser_js_1.closeBrowser)();
|
||||
process.exit(0);
|
||||
};
|
||||
process.on("SIGTERM", shutdown);
|
||||
process.on("SIGINT", shutdown);
|
||||
}
|
||||
start().catch((err) => {
|
||||
console.error("Failed to start:", err);
|
||||
process.exit(1);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue