Initial commit: everythingbutwork MVP
Internes Project-Management-Tool für ToolCTRL — ergänzend zu Plane (Tickets) und Outline (Doku). Umfasst Puls-Übersicht, Tagesrhythmus (Lock-in + Reflexion), Bereichs-Detail-Views (Entwicklung/Vertrieb/Marketing), Pflicht-Minimum-Check und Blocker-Lifecycle gemäß Projektmanagement-Leitfaden v3.0. Stack: pnpm-Monorepo · Vite + React 18 + Tailwind · Fastify + tRPC v11 + Drizzle ORM · Postgres 16 · Authentik OIDC (Phase 2, Dev-Auto-Login aktiv). Planungs-Artefakte unter _bmad-output/planning-artifacts/. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
4f33509a0f
131 files changed
+34339
No files matched your search
@@ -0,0 +1,91 @@
|
||||
import Fastify from 'fastify';
|
||||
import cookie from '@fastify/cookie';
|
||||
import { fastifyTRPCPlugin, type FastifyTRPCPluginOptions } from '@trpc/server/adapters/fastify';
|
||||
import { loadEnv } from './env.js';
|
||||
import { logger } from './lib/logger.js';
|
||||
import { registerAuthMiddleware } from './auth/middleware.js';
|
||||
import { registerAuthRoutes } from './auth/routes.js';
|
||||
import { registerCronRoutes } from './cron/routes.js';
|
||||
import { getDb } from './db.js';
|
||||
import { appRouter, type AppRouter } from './routers/_app.js';
|
||||
import { createContext } from './trpc.js';
|
||||
|
||||
async function main() {
|
||||
const env = loadEnv();
|
||||
const app = Fastify({
|
||||
logger: {
|
||||
level: env.LOG_LEVEL,
|
||||
base: { service: 'cockpit-api' },
|
||||
},
|
||||
});
|
||||
|
||||
await app.register(cookie, {
|
||||
secret: env.SESSION_COOKIE_SECRET,
|
||||
});
|
||||
|
||||
await registerAuthMiddleware(app);
|
||||
await registerAuthRoutes(app);
|
||||
await registerCronRoutes(app);
|
||||
|
||||
await app.register(fastifyTRPCPlugin, {
|
||||
prefix: '/trpc',
|
||||
trpcOptions: {
|
||||
router: appRouter,
|
||||
createContext,
|
||||
onError({ path, error }) {
|
||||
logger.error({ path, err: error }, 'trpc error');
|
||||
},
|
||||
} satisfies FastifyTRPCPluginOptions<AppRouter>['trpcOptions'],
|
||||
});
|
||||
|
||||
app.get('/api/health', async () => {
|
||||
const { pool } = getDb();
|
||||
let dbOk = false;
|
||||
try {
|
||||
await pool.query('SELECT 1');
|
||||
dbOk = true;
|
||||
} catch (err) {
|
||||
logger.warn({ err }, 'db ping failed');
|
||||
}
|
||||
|
||||
let authentikOk = false;
|
||||
try {
|
||||
const res = await fetch(new URL('.well-known/openid-configuration', env.AUTHENTIK_ISSUER), {
|
||||
signal: AbortSignal.timeout(3_000),
|
||||
});
|
||||
authentikOk = res.ok;
|
||||
} catch (err) {
|
||||
logger.warn({ err }, 'authentik ping failed');
|
||||
}
|
||||
|
||||
const status = dbOk && authentikOk ? 'ok' : 'degraded';
|
||||
return {
|
||||
status,
|
||||
db: dbOk ? 'ok' : 'down',
|
||||
authentik: authentikOk ? 'ok' : 'down',
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
});
|
||||
|
||||
app.get('/api/me', async (req, reply) => {
|
||||
if (!req.cockpitUser) {
|
||||
reply.code(401);
|
||||
return { error: 'Nicht angemeldet.' };
|
||||
}
|
||||
return {
|
||||
id: req.cockpitUser.id,
|
||||
name: req.cockpitUser.name,
|
||||
email: req.cockpitUser.email,
|
||||
};
|
||||
});
|
||||
|
||||
try {
|
||||
await app.listen({ port: env.PORT, host: '0.0.0.0' });
|
||||
logger.info({ port: env.PORT }, 'api server started');
|
||||
} catch (err) {
|
||||
logger.error(err, 'failed to start api server');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in new issue
Block a user