Changes
This commit is contained in:
65
src/index.ts
Normal file
65
src/index.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import Fastify from "fastify";
|
||||
import swaggerPlugin from "./plugins/swagger"
|
||||
import supabasePlugin from "./plugins/supabase";
|
||||
import healthRoutes from "./routes/health";
|
||||
import meRoutes from "./routes/me";
|
||||
import tenantRoutes from "./routes/tenant";
|
||||
import tenantPlugin from "./plugins/tenant";
|
||||
import authRoutes from "./routes/auth";
|
||||
import authRoutesAuthenticated from "./routes/auth-authenticated";
|
||||
import authPlugin from "./plugins/auth";
|
||||
import adminRoutes from "./routes/admin";
|
||||
import corsPlugin from "./plugins/cors";
|
||||
import resourceRoutes from "./routes/resources";
|
||||
import fastifyCookie from "@fastify/cookie";
|
||||
import historyRoutes from "./routes/history";
|
||||
|
||||
import {sendMail} from "./utils/mailer";
|
||||
|
||||
async function main() {
|
||||
const app = Fastify({ logger: true });
|
||||
|
||||
/*app.addHook("onRequest", (req, reply, done) => {
|
||||
console.log("Incoming:", req.method, req.url, "Headers:", req.headers)
|
||||
done()
|
||||
})*/
|
||||
|
||||
// Plugins Global verfügbar
|
||||
await app.register(swaggerPlugin);
|
||||
await app.register(corsPlugin);
|
||||
await app.register(supabasePlugin);
|
||||
await app.register(tenantPlugin);
|
||||
app.register(fastifyCookie, {
|
||||
secret: process.env.COOKIE_SECRET || "supersecret", // optional, für signierte Cookies
|
||||
})
|
||||
// Öffentliche Routes
|
||||
await app.register(authRoutes);
|
||||
await app.register(healthRoutes);
|
||||
|
||||
|
||||
|
||||
//Geschützte Routes
|
||||
|
||||
await app.register(async (subApp) => {
|
||||
await subApp.register(authPlugin);
|
||||
await subApp.register(authRoutesAuthenticated);
|
||||
await subApp.register(meRoutes);
|
||||
await subApp.register(tenantRoutes);
|
||||
await subApp.register(adminRoutes);
|
||||
await subApp.register(resourceRoutes);
|
||||
await subApp.register(historyRoutes);
|
||||
|
||||
},{prefix: "/api"})
|
||||
|
||||
|
||||
// Start
|
||||
try {
|
||||
await app.listen({ port: 3100 });
|
||||
console.log("🚀 Server läuft auf http://localhost:3100");
|
||||
} catch (err) {
|
||||
app.log.error(err);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user