This commit is contained in:
Chocobozzz 2020-09-02 16:24:25 +02:00
parent a39fe6af6a
commit 4f3b473d51
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 14 additions and 5 deletions

View File

@ -10,7 +10,7 @@ import * as cors from 'cors'
import * as morgan from 'morgan' import * as morgan from 'morgan'
import { apiRouter } from './server/controllers/api' import { apiRouter } from './server/controllers/api'
import { logger } from './server/helpers/logger' 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 { VideosIndexer } from './server/lib/schedulers/videos-indexer'
import { initVideosIndex } from './server/lib/elastic-search-videos' import { initVideosIndex } from './server/lib/elastic-search-videos'
import { initChannelsIndex } from './server/lib/elastic-search-channels' 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 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 title = CONFIG.SEARCH_INSTANCE.NAME
const description = CONFIG.SEARCH_INSTANCE.DESCRIPTION const description = CONFIG.SEARCH_INSTANCE.DESCRIPTION

View File

@ -1,15 +1,14 @@
import * as Bluebird from 'bluebird' import * as Bluebird from 'bluebird'
import * as request from 'request' import * as request from 'request'
import { getWebserverUrl } from '../initializers/constants'
import { waitMs } from './core-utils' import { waitMs } from './core-utils'
import { CONFIG } from '../initializers/constants'
function doRequest <T> ( function doRequest <T> (
requestOptions: request.CoreOptions & request.UriOptions requestOptions: request.CoreOptions & request.UriOptions
): Bluebird<{ response: request.RequestResponse, body: T }> { ): Bluebird<{ response: request.RequestResponse, body: T }> {
if (!(requestOptions.headers)) requestOptions.headers = {} if (!(requestOptions.headers)) requestOptions.headers = {}
const webserverUrl = CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT requestOptions.headers['User-Agent'] = `PeerTube search index (+${getWebserverUrl()})`
requestOptions.headers['User-Agent'] = `PeerTube search index (+${webserverUrl})`
return new Bluebird<{ response: request.RequestResponse, body: T }>((res, rej) => { return new Bluebird<{ response: request.RequestResponse, body: T }>((res, rej) => {
request(requestOptions, (err, response, body) => err ? rej(err) : res({ response, body })) request(requestOptions, (err, response, body) => err ? rej(err) : res({ response, body }))

View File

@ -68,11 +68,21 @@ const REQUESTS = {
WAIT: 10000 // 10 seconds 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()) { if (isTestInstance()) {
SCHEDULER_INTERVALS_MS.videosIndexer = 1000 * 60 * 5 // 5 minutes SCHEDULER_INTERVALS_MS.videosIndexer = 1000 * 60 * 5 // 5 minutes
} }
export { export {
getWebserverUrl,
CONFIG, CONFIG,
API_VERSION, API_VERSION,
PAGINATION_COUNT_DEFAULT, PAGINATION_COUNT_DEFAULT,