import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import { serverConfig } from './config'; import * as session from 'express-session'; import { join } from 'path'; import { NestExpressApplication } from '@nestjs/platform-express'; import * as fs from 'fs'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.enableCors(); // ✅ API prefix app.setGlobalPrefix('api'); // <<==== All controllers now under /api/* const angularDistPath = join(__dirname, '..', '..', 'web-app', 'dist', 'mobile-auth-web-app', 'browser'); const indexPath = join(angularDistPath, 'index.html'); console.log('✅ Angular path:', angularDistPath); console.log('✅ index.html exists:', fs.existsSync(indexPath)); // ✅ Now serve Angular static files app.useStaticAssets(angularDistPath); app.setBaseViewsDir(angularDistPath); app.setViewEngine('html'); app.use( session({ secret: 'your-secret', resave: false, saveUninitialized: false, }), ); // ✅ Angular fallback: only for non-API, non-static requests app.use((req, res, next) => { const isStaticAsset = req.url.includes('.'); const isApiCall = req.url.startsWith('/api') || req.method !== 'GET'; if (isStaticAsset || isApiCall) { return next(); } console.log('📦 Angular fallback hit for:', req.url); res.sendFile(indexPath); }); await app.listen(process.env.PORT ?? 3000); console.log(`🚀 Server running at http://localhost:3000`); console.log(`🌐 Exposed at: ${serverConfig.exposedUrl}`); } bootstrap();