stuff
This commit is contained in:
parent
3b879f80d4
commit
178a2ba23b
2 changed files with 28 additions and 1 deletions
|
|
@ -179,6 +179,11 @@ Frontend: http://localhost:5173
|
||||||
- Backend: `https://api.example.com`
|
- Backend: `https://api.example.com`
|
||||||
- `CORS_ORIGIN` должен быть: `https://example.com`
|
- `CORS_ORIGIN` должен быть: `https://example.com`
|
||||||
|
|
||||||
|
**Поддержка нескольких origins:** Можно указать несколько доменов через запятую:
|
||||||
|
```
|
||||||
|
CORS_ORIGIN=https://party-games.online,https://www.party-games.online,http://localhost:5173
|
||||||
|
```
|
||||||
|
|
||||||
### Frontend переменные:
|
### Frontend переменные:
|
||||||
- `VITE_API_URL` - URL backend API (по умолчанию http://localhost:3000)
|
- `VITE_API_URL` - URL backend API (по умолчанию http://localhost:3000)
|
||||||
- `VITE_WS_URL` - URL WebSocket сервера (по умолчанию http://localhost:3000)
|
- `VITE_WS_URL` - URL WebSocket сервера (по умолчанию http://localhost:3000)
|
||||||
|
|
@ -275,6 +280,7 @@ npm run preview # Preview build
|
||||||
- [Backend README](backend/README.md) - детальная документация backend
|
- [Backend README](backend/README.md) - детальная документация backend
|
||||||
- [PLAN.md](PLAN.md) - полный план разработки
|
- [PLAN.md](PLAN.md) - полный план разработки
|
||||||
- [API Documentation](backend/README.md#-api-endpoints) - REST и WebSocket API
|
- [API Documentation](backend/README.md#-api-endpoints) - REST и WebSocket API
|
||||||
|
- [TROUBLESHOOTING.md](TROUBLESHOOTING.md) - решение проблем с деплоем (502 ошибки, CORS и т.д.)
|
||||||
|
|
||||||
## 🎨 Особенности
|
## 🎨 Особенности
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,29 @@ async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule);
|
const app = await NestFactory.create(AppModule);
|
||||||
const configService = app.get(ConfigService);
|
const configService = app.get(ConfigService);
|
||||||
|
|
||||||
|
// Поддержка нескольких origins через запятую или одного origin
|
||||||
|
const corsOrigin = configService.get<string>('CORS_ORIGIN') || 'http://localhost:5173';
|
||||||
|
const allowedOrigins = corsOrigin.split(',').map(origin => origin.trim());
|
||||||
|
|
||||||
app.enableCors({
|
app.enableCors({
|
||||||
origin: configService.get<string>('CORS_ORIGIN') || 'http://localhost:5173',
|
origin: (origin, callback) => {
|
||||||
|
// Разрешаем запросы без origin (например, Postman, мобильные приложения)
|
||||||
|
if (!origin) {
|
||||||
|
return callback(null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверяем, есть ли origin в списке разрешенных
|
||||||
|
if (allowedOrigins.includes(origin)) {
|
||||||
|
return callback(null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Логируем отклоненные запросы для отладки
|
||||||
|
console.warn(`CORS: Blocked origin: ${origin}. Allowed origins: ${allowedOrigins.join(', ')}`);
|
||||||
|
return callback(new Error('Not allowed by CORS'));
|
||||||
|
},
|
||||||
credentials: true,
|
credentials: true,
|
||||||
|
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
|
||||||
|
allowedHeaders: ['Content-Type', 'Authorization'],
|
||||||
});
|
});
|
||||||
|
|
||||||
app.useGlobalPipes(new ValidationPipe({
|
app.useGlobalPipes(new ValidationPipe({
|
||||||
|
|
@ -21,5 +41,6 @@ async function bootstrap() {
|
||||||
const host = configService.get<string>('HOST') || '0.0.0.0';
|
const host = configService.get<string>('HOST') || '0.0.0.0';
|
||||||
await app.listen(port, host);
|
await app.listen(port, host);
|
||||||
console.log(`Backend running on http://${host}:${port}`);
|
console.log(`Backend running on http://${host}:${port}`);
|
||||||
|
console.log(`CORS allowed origins: ${allowedOrigins.join(', ')}`);
|
||||||
}
|
}
|
||||||
bootstrap();
|
bootstrap();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue