Hosting: stos fitos-alt na alternatywnym urzadzeniu (remote/deploy.ps1, porty 13xxx) + CORS_EXTRA_ORIGINS dla dostepu po IP
This commit is contained in:
@@ -30,9 +30,41 @@ export function assertProductionSecrets(cfg: SecretsGuardInput): void {
|
||||
}
|
||||
}
|
||||
|
||||
function escapeRegexLiteral(value: string): string {
|
||||
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
|
||||
/**
|
||||
* CORS_EXTRA_ORIGINS: lista dokładnych originów oddzielonych przecinkiem,
|
||||
* np. "http://192.168.50.127:13002,http://192.168.50.127:13003" — używana gdy
|
||||
* apka jest hostowana poza główną domeną (host na alternatywnym urządzeniu).
|
||||
*/
|
||||
export function parseExtraCorsOrigins(raw: string | undefined): string[] {
|
||||
return (raw ?? '')
|
||||
.split(',')
|
||||
.map((s) => s.trim())
|
||||
.filter((s) => s.length > 0);
|
||||
}
|
||||
|
||||
export function buildCorsOriginPatterns(nodeEnv: string, extraOrigins: string[]): RegExp[] {
|
||||
return [
|
||||
/^https?:\/\/(www\.)?domena\.pl(:\d+)?$/,
|
||||
/^https?:\/\/admin\.domena\.pl(:\d+)?$/,
|
||||
/^https?:\/\/(www\.)?tisachi\.ddns\.net(:\d+)?$/,
|
||||
// dodatkowe origins traktujemy dosłownie (escapowane) — pełne dopasowanie originu
|
||||
...extraOrigins.map((o) => new RegExp(`^${escapeRegexLiteral(o)}$`)),
|
||||
// localhost tylko poza produkcją (dev/testy e2e); w produkcji originy wyłącznie znad domeny
|
||||
...(nodeEnv === 'production'
|
||||
? []
|
||||
: [/^https?:\/\/localhost(:\d+)?$/, /^https?:\/\/127\.0\.0\.1(:\d+)?$/]),
|
||||
];
|
||||
}
|
||||
|
||||
const nodeEnv = process.env.NODE_ENV || 'development';
|
||||
|
||||
export const config = {
|
||||
port: parseInt(process.env.PORT || '9002', 10),
|
||||
nodeEnv: process.env.NODE_ENV || 'development',
|
||||
nodeEnv,
|
||||
databaseUrl: process.env.DATABASE_URL || 'postgresql://fitos:fitos@localhost:5432/fitos',
|
||||
jwt: {
|
||||
accessSecret: process.env.JWT_ACCESS_SECRET || 'dev-access-secret',
|
||||
@@ -44,15 +76,10 @@ export const config = {
|
||||
uploadDir: process.env.UPLOAD_DIR || path.join(process.cwd(), 'uploads'),
|
||||
// true only when served over HTTPS — over plain HTTP browsers drop Secure cookies (breaks refresh)
|
||||
cookieSecure: process.env.COOKIE_SECURE === 'true',
|
||||
corsOriginPatterns: [
|
||||
/^https?:\/\/(www\.)?domena\.pl(:\d+)?$/,
|
||||
/^https?:\/\/admin\.domena\.pl(:\d+)?$/,
|
||||
/^https?:\/\/(www\.)?tisachi\.ddns\.net(:\d+)?$/,
|
||||
// localhost tylko poza produkcją (dev/testy e2e); w produkcji originy wyłącznie znad domeny
|
||||
...(process.env.NODE_ENV === 'production'
|
||||
? []
|
||||
: [/^https?:\/\/localhost(:\d+)?$/, /^https?:\/\/127\.0\.0\.1(:\d+)?$/]),
|
||||
],
|
||||
corsOriginPatterns: buildCorsOriginPatterns(
|
||||
nodeEnv,
|
||||
parseExtraCorsOrigins(process.env.CORS_EXTRA_ORIGINS),
|
||||
),
|
||||
};
|
||||
|
||||
if (config.nodeEnv === 'production') {
|
||||
|
||||
Reference in New Issue
Block a user