diff options
Diffstat (limited to 'packages/backend/src/config.ts')
| -rw-r--r-- | packages/backend/src/config.ts | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index c2e7efd456..06f73fdb21 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -30,6 +30,8 @@ type RedisOptionsSource = Partial<RedisOptions> & { */ type Source = { url?: string; + localUrl?: string; + webUrl?: string; port?: number; address?: string; socket?: string; @@ -214,7 +216,8 @@ function parseIpOrMask(ipOrMask: string): CIDR | null { } export type Config = { - url: string; + localUrl: string; + webUrl: string; port: number; address: string; socket: string | undefined; @@ -290,8 +293,10 @@ export type Config = { version: string; publishTarballInsteadOfProvideRepositoryUrl: boolean; setupPassword: string | undefined; - host: string; - hostname: string; + localHost: string; + localHostname: string; + webHost: string; + webHostname: string; scheme: string; wsScheme: string; apiUrl: string; @@ -396,11 +401,14 @@ export function loadConfig(): Config { applyEnvOverrides(config); - const url = tryCreateUrl(config.url ?? process.env.MISSKEY_URL ?? ''); + const localUrl = tryCreateUrl(config.url ?? config.localUrl ?? process.env.MISSKEY_URL ?? ''); + const webUrl = tryCreateUrl(config.webUrl ?? process.env.MISSKEY_WEB_URL ?? localUrl ?? ''); const version = meta.version; - const host = url.host; - const hostname = url.hostname; - const scheme = url.protocol.replace(/:$/, ''); + const localHost = localUrl.host; + const localHostname = localUrl.hostname; + const webHost = webUrl.host; + const webHostname = webUrl.hostname; + const scheme = webUrl.protocol.replace(/:$/, ''); const wsScheme = scheme.replace('http', 'ws'); const dbDb = config.db.db ?? process.env.DATABASE_DB ?? ''; @@ -410,8 +418,8 @@ export function loadConfig(): Config { const externalMediaProxy = config.mediaProxy ? config.mediaProxy.endsWith('/') ? config.mediaProxy.substring(0, config.mediaProxy.length - 1) : config.mediaProxy : null; - const internalMediaProxy = `${scheme}://${host}/proxy`; - const redis = convertRedisOptions(config.redis, host); + const internalMediaProxy = `${scheme}://${webHost}/proxy`; + const redis = convertRedisOptions(config.redis, localHost); // nullish => 300 (default) // 0 => undefined (disabled) @@ -421,31 +429,34 @@ export function loadConfig(): Config { version, publishTarballInsteadOfProvideRepositoryUrl: !!config.publishTarballInsteadOfProvideRepositoryUrl, setupPassword: config.setupPassword, - url: url.origin, + localUrl: localUrl.origin, + webUrl: webUrl.origin, port: config.port ?? parseInt(process.env.PORT ?? '3000', 10), address: config.address ?? '0.0.0.0', socket: config.socket, chmodSocket: config.chmodSocket, disableHsts: config.disableHsts, - host, - hostname, + localHost, + localHostname, + webHost, + webHostname, scheme, wsScheme, - wsUrl: `${wsScheme}://${host}`, - apiUrl: `${scheme}://${host}/api`, - authUrl: `${scheme}://${host}/auth`, - driveUrl: `${scheme}://${host}/files`, + wsUrl: `${wsScheme}://${webHost}`, + apiUrl: `${scheme}://${webHost}/api`, + authUrl: `${scheme}://${webHost}/auth`, + driveUrl: `${scheme}://${webHost}/files`, db: { ...config.db, db: dbDb, user: dbUser, pass: dbPass, slowQueryThreshold }, dbReplications: config.dbReplications, dbSlaves: config.dbSlaves, fulltextSearch: config.fulltextSearch, meilisearch: config.meilisearch, redis, - redisForPubsub: config.redisForPubsub ? convertRedisOptions(config.redisForPubsub, host) : redis, - redisForJobQueue: config.redisForJobQueue ? convertRedisOptions(config.redisForJobQueue, host) : redis, - redisForTimelines: config.redisForTimelines ? convertRedisOptions(config.redisForTimelines, host) : redis, - redisForReactions: config.redisForReactions ? convertRedisOptions(config.redisForReactions, host) : redis, - redisForRateLimit: config.redisForRateLimit ? convertRedisOptions(config.redisForRateLimit, host) : redis, + redisForPubsub: config.redisForPubsub ? convertRedisOptions(config.redisForPubsub, webHost) : redis, + redisForJobQueue: config.redisForJobQueue ? convertRedisOptions(config.redisForJobQueue, webHost) : redis, + redisForTimelines: config.redisForTimelines ? convertRedisOptions(config.redisForTimelines, webHost) : redis, + redisForReactions: config.redisForReactions ? convertRedisOptions(config.redisForReactions, webHost) : redis, + redisForRateLimit: config.redisForRateLimit ? convertRedisOptions(config.redisForRateLimit, webHost) : redis, sentryForBackend: config.sentryForBackend, sentryForFrontend: config.sentryForFrontend, id: config.id, @@ -483,7 +494,7 @@ export function loadConfig(): Config { videoThumbnailGenerator: config.videoThumbnailGenerator ? config.videoThumbnailGenerator.endsWith('/') ? config.videoThumbnailGenerator.substring(0, config.videoThumbnailGenerator.length - 1) : config.videoThumbnailGenerator : null, - userAgent: `Misskey/${version} (${config.url})`, + userAgent: `Misskey/${version} (${config.localUrl})`, frontendEntry: frontendManifest['src/_boot_.ts'], frontendManifestExists: frontendManifestExists, frontendEmbedEntry: frontendEmbedManifest['src/boot.ts'], |