sepia-search-motore-di-rice.../server/helpers/elastic-search.ts

31 lines
712 B
TypeScript
Raw Normal View History

2021-02-03 11:51:05 +01:00
import { readFileSync } from 'fs-extra'
2021-06-24 15:18:54 +02:00
import { Client } from '@elastic/elasticsearch'
2020-02-13 11:49:03 +01:00
import { CONFIG } from '../initializers/constants'
2021-02-03 11:49:26 +01:00
const elasticOptions = {
node: CONFIG.ELASTIC_SEARCH.HTTP + '://' + CONFIG.ELASTIC_SEARCH.HOSTNAME + ':' + CONFIG.ELASTIC_SEARCH.PORT
}
if (CONFIG.ELASTIC_SEARCH.SSL.CA) {
2021-02-03 11:51:05 +01:00
Object.assign(elasticOptions, {
2022-11-15 14:18:28 +01:00
tls: {
2021-02-03 11:51:05 +01:00
ca: readFileSync(CONFIG.ELASTIC_SEARCH.SSL.CA)
}
})
2021-02-03 11:49:26 +01:00
}
2021-02-04 08:55:02 +01:00
if (CONFIG.ELASTIC_SEARCH.AUTH.USERNAME) {
Object.assign(elasticOptions, {
auth: {
username: CONFIG.ELASTIC_SEARCH.AUTH.USERNAME,
password: CONFIG.ELASTIC_SEARCH.AUTH.PASSWORD
}
})
}
2021-02-03 11:49:26 +01:00
const elasticSearch = new Client(elasticOptions)
2020-02-13 11:49:03 +01:00
export {
2021-06-24 15:18:54 +02:00
elasticSearch
2020-02-13 11:49:03 +01:00
}