feat(backend): bootstrap NestJS app with dummy auth and health endpoint

This commit is contained in:
admin committed 2025-12-26 12:42:10 +01:00
1 parent fb4c442542
commit c0a814081d
8 files changed
+2420 -18

No files matched your search

+2345 -2
View File
File diff suppressed because it is too large. Load diff
+16 -2
View File
@@ -1,9 +1,23 @@
{
"prisma": {
"name": "onlypets-backend",
"version": "1.0.0",
"scripts": {
"dev": "ts-node src/main.ts",
"start": "node dist/main.js",
"build": "tsc",
"seed": "ts-node prisma/seed.ts"
},
"dependencies": {
"@nestjs/core": "11.1.10",
"@nestjs/platform-express": "^11.1.10",
"@prisma/client": "^6.19.1",
"prisma": "^6.19.1"
"express": "^4.17.1",
"prisma": "^6.19.1",
"ts-node": "^10.9.2",
"typescript": "^5.9.3"
},
"devDependencies": {
"@types/express": "^5.0.6",
"nodemon": "^3.1.11"
}
}
+2
View File
@@ -2,9 +2,11 @@ import { Module } from '@nestjs/common';
import { APP_GUARD } from '@nestjs/core';
import { DummyAuthGuard } from './auth/guards/dummy-auth.guard';
import { HealthController } from './health.controller';
@Module({
imports: [],
controllers: [HealthController],
providers: [
{
provide: APP_GUARD,
+7 -11
View File
@@ -1,11 +1,5 @@
import {
CanActivate,
ExecutionContext,
Injectable,
} from '@nestjs/common';
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { Request } from 'express';
import { IS_PUBLIC_KEY } from '../decorators/public.decorator';
import { RequestUser, UserRole } from '../types/request-user.type';
@@ -19,21 +13,23 @@ export class DummyAuthGuard implements CanActivate {
[context.getHandler(), context.getClass()],
);
const request = context.switchToHttp().getRequest<Request>();
const request = context.switchToHttp().getRequest();
// Öffentliche Route → kein User nötig
if (isPublic) {
request.user = null;
return true;
}
// Dummy-Auth nur aktiv, wenn explizit gesetzt
if (process.env.AUTH_MODE !== 'dummy') {
request.user = null;
return true;
}
const role = (process.env.DEV_FAKE_USER_ROLE as UserRole) ?? 'USER';
const rawRole = process.env.DEV_FAKE_USER_ROLE;
const role: UserRole =
rawRole === 'ADMIN' || rawRole === 'MOD' || rawRole === 'USER'
? rawRole
: 'USER';
const fakeUser: RequestUser = {
id: Number(process.env.DEV_FAKE_USER_ID ?? 0),
+14
View File
@@ -0,0 +1,14 @@
import { Controller, Get } from '@nestjs/common';
import { Public } from './auth/decorators/public.decorator';
@Controller()
export class HealthController {
@Public()
@Get('/health')
health() {
return {
status: 'ok',
timestamp: new Date().toISOString(),
};
}
}
+13
View File
@@ -0,0 +1,13 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const port = process.env.PORT || 3000;
await app.listen(port);
console.log(`🚀 Backend running on http://localhost:${port}`);
}
bootstrap();
+7 -3
View File
@@ -1,7 +1,11 @@
import { RequestUser } from '../auth/types/request-user.type';
declare module 'express' {
interface Request {
user?: RequestUser | null;
declare global {
namespace Express {
interface Request {
user?: RequestUser | null;
}
}
}
export {};
+16
View File
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "CommonJS",
"target": "ES2021",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "dist",
"typeRoots": ["./node_modules/@types", "./src/types"]
},
"include": ["src/**/*.ts"]
}