mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
37 lines
895 B
TypeScript
37 lines
895 B
TypeScript
import Fastify from "fastify";
|
|||
|
|
import cors from "@fastify/cors";
|
||
|
|
import rateLimit from "@fastify/rate-limit";
|
||
|
|
import { env } from "./config.js";
|
||
|
|
import { APP_VERSION } from "@stirling-image/shared";
|
||
|
|
|
||
|
|
const app = Fastify({
|
||
|
|
logger: true,
|
||
|
|
bodyLimit: env.MAX_UPLOAD_SIZE_MB * 1024 * 1024,
|
||
|
|
});
|
||
|
|
|
||
|
|
// Plugins
|
||
|
|
await app.register(cors, { origin: true });
|
||
|
|
await app.register(rateLimit, {
|
||
|
|
max: env.RATE_LIMIT_PER_MIN,
|
||
|
|
timeWindow: "1 minute",
|
||
|
|
});
|
||
|
|
|
||
|
|
// Health check
|
||
|
|
app.get("/api/v1/health", async () => ({
|
||
|
|
status: "healthy",
|
||
|
|
version: APP_VERSION,
|
||
|
|
uptime: process.uptime().toFixed(0) + "s",
|
||
|
|
storage: { mode: env.STORAGE_MODE, available: "N/A" },
|
||
|
|
queue: { active: 0, pending: 0 },
|
||
|
|
ai: {},
|
||
|
|
}));
|
||
|
|
|
||
|
|
// Start
|
||
|
|
try {
|
||
|
|
await app.listen({ port: env.PORT, host: "0.0.0.0" });
|
||
|
|
console.log(`Stirling Image API running on port ${env.PORT}`);
|
||
|
|
} catch (err) {
|
||
|
|
app.log.error(err);
|
||
|
|
process.exit(1);
|
||
|
|
}
|