From 4f3b473d512bd146967010f8edc8f2dbe92bf90c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 2 Sep 2020 16:24:25 +0200 Subject: [PATCH] Fix URL --- server.ts | 4 ++-- server/helpers/requests.ts | 5 ++--- server/initializers/constants.ts | 10 ++++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/server.ts b/server.ts index 7ef6cf1..df92ae8 100644 --- a/server.ts +++ b/server.ts @@ -10,7 +10,7 @@ import * as cors from 'cors' import * as morgan from 'morgan' import { apiRouter } from './server/controllers/api' import { logger } from './server/helpers/logger' -import { API_VERSION, CONFIG } from './server/initializers/constants' +import { API_VERSION, CONFIG, getWebserverUrl } from './server/initializers/constants' import { VideosIndexer } from './server/lib/schedulers/videos-indexer' import { initVideosIndex } from './server/lib/elastic-search-videos' import { initChannelsIndex } from './server/lib/elastic-search-channels' @@ -51,7 +51,7 @@ app.use('/*', async function (req, res) { const buffer = await readFile(join(__dirname, '../client/dist/index.html')) - const url = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT + const url = getWebserverUrl() const title = CONFIG.SEARCH_INSTANCE.NAME const description = CONFIG.SEARCH_INSTANCE.DESCRIPTION diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index fef7f2e..07dad43 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts @@ -1,15 +1,14 @@ import * as Bluebird from 'bluebird' import * as request from 'request' +import { getWebserverUrl } from '../initializers/constants' import { waitMs } from './core-utils' -import { CONFIG } from '../initializers/constants' function doRequest ( requestOptions: request.CoreOptions & request.UriOptions ): Bluebird<{ response: request.RequestResponse, body: T }> { if (!(requestOptions.headers)) requestOptions.headers = {} - const webserverUrl = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT - requestOptions.headers['User-Agent'] = `PeerTube search index (+${webserverUrl})` + requestOptions.headers['User-Agent'] = `PeerTube search index (+${getWebserverUrl()})` return new Bluebird<{ response: request.RequestResponse, body: T }>((res, rej) => { request(requestOptions, (err, response, body) => err ? rej(err) : res({ response, body })) diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index ae81c03..62c7b7f 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -68,11 +68,21 @@ const REQUESTS = { WAIT: 10000 // 10 seconds } +function getWebserverUrl () { + if (CONFIG.WEBSERVER.PORT === 80 || CONFIG.WEBSERVER.PORT === 443) { + return CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + } + + return CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT +} + if (isTestInstance()) { SCHEDULER_INTERVALS_MS.videosIndexer = 1000 * 60 * 5 // 5 minutes } export { + getWebserverUrl, + CONFIG, API_VERSION, PAGINATION_COUNT_DEFAULT,