business: DocFast deployed on Hetzner CAX11 (167.235.156.214)
This commit is contained in:
parent
37094c8945
commit
a1c86b0ebc
13 changed files with 181 additions and 111 deletions
60
projects/business/src/pdf-api/dist/index.js
vendored
60
projects/business/src/pdf-api/dist/index.js
vendored
|
|
@ -1,25 +1,22 @@
|
|||
"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;
|
||||
import express from "express";
|
||||
import helmet from "helmet";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import rateLimit from "express-rate-limit";
|
||||
import { convertRouter } from "./routes/convert.js";
|
||||
import { templatesRouter } from "./routes/templates.js";
|
||||
import { healthRouter } from "./routes/health.js";
|
||||
import { authMiddleware } from "./middleware/auth.js";
|
||||
import { usageMiddleware } from "./middleware/usage.js";
|
||||
import { getUsageStats } from "./middleware/usage.js";
|
||||
import { initBrowser, closeBrowser } from "./services/browser.js";
|
||||
const app = express();
|
||||
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/*" }));
|
||||
app.use(helmet());
|
||||
app.use(express.json({ limit: "2mb" }));
|
||||
app.use(express.text({ limit: "2mb", type: "text/*" }));
|
||||
// Rate limiting: 100 req/min for free tier
|
||||
const limiter = (0, express_rate_limit_1.default)({
|
||||
const limiter = rateLimit({
|
||||
windowMs: 60_000,
|
||||
max: 100,
|
||||
standardHeaders: true,
|
||||
|
|
@ -27,12 +24,19 @@ const limiter = (0, express_rate_limit_1.default)({
|
|||
});
|
||||
app.use(limiter);
|
||||
// Public
|
||||
app.use("/health", health_js_1.healthRouter);
|
||||
app.use("/health", 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) => {
|
||||
app.use("/v1/convert", authMiddleware, usageMiddleware, convertRouter);
|
||||
app.use("/v1/templates", authMiddleware, usageMiddleware, templatesRouter);
|
||||
// Admin: usage stats (protected by auth)
|
||||
app.get("/v1/usage", authMiddleware, (_req, res) => {
|
||||
res.json(getUsageStats());
|
||||
});
|
||||
// Landing page
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
app.use(express.static(path.join(__dirname, "../public")));
|
||||
// API root (for programmatic discovery)
|
||||
app.get("/api", (_req, res) => {
|
||||
res.json({
|
||||
name: "DocFast API",
|
||||
version: "0.1.0",
|
||||
|
|
@ -40,17 +44,18 @@ app.get("/", (_req, res) => {
|
|||
endpoints: [
|
||||
"POST /v1/convert/html",
|
||||
"POST /v1/convert/markdown",
|
||||
"POST /v1/convert/url",
|
||||
"POST /v1/templates/:id/render",
|
||||
"GET /v1/templates",
|
||||
],
|
||||
});
|
||||
});
|
||||
async function start() {
|
||||
await (0, browser_js_1.initBrowser)();
|
||||
await initBrowser();
|
||||
app.listen(PORT, () => console.log(`DocFast API running on :${PORT}`));
|
||||
const shutdown = async () => {
|
||||
console.log("Shutting down...");
|
||||
await (0, browser_js_1.closeBrowser)();
|
||||
await closeBrowser();
|
||||
process.exit(0);
|
||||
};
|
||||
process.on("SIGTERM", shutdown);
|
||||
|
|
@ -60,3 +65,4 @@ start().catch((err) => {
|
|||
console.error("Failed to start:", err);
|
||||
process.exit(1);
|
||||
});
|
||||
export { app };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue