From c2e4899d3c50c1fe82f69b8af5029efff3821d9c Mon Sep 17 00:00:00 2001 From: David Ball Date: Mon, 24 Jun 2024 21:54:40 -0400 Subject: [PATCH] feat: Trim slashes on all .env config URLs, SITE_URL, SOLR_DOCS_URL, TIKA_URL, etc. --- app/config.mts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/config.mts b/app/config.mts index 9ff45f88..74f48d2f 100644 --- a/app/config.mts +++ b/app/config.mts @@ -187,6 +187,9 @@ import dotenv from 'dotenv'; import dotenvExpand from 'dotenv-expand'; import process from 'process'; import { fileURLToPath } from 'url'; +export const trimSlashes = (dirPath: string) => { + return dirPath.replace(/^[\/\\]|[\/\\]$/g, ''); +}; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -212,7 +215,7 @@ export const getAppHttpUrl = () => { export const getSiteName = () => env.SITE_NAME||"(dev) No Moss 3 Carbo Landfill Online Localhost"; export const getSiteWelcomeMessage = () => env.SITE_WELCOME_MESSAGE||"Devel' It Up, Developer!"; export const getSiteHost = () => env.SITE_HOST||"localhost"; -export const getSiteUrl = () => env.SITE_URL||getAppHttpUrl(); +export const getSiteUrl = () => trimSlashes(env.SITE_URL||getAppHttpUrl()); // Note the difference: PUBLIC_PATH is expected to be one level above the project folder and PAGES_PATH, STATIC_PATH, and VIEWS_PATH are all copied from src/ to dist/. export const getPublicPath = () => path.join(__dirname, '..', '..', (env.PUBLIC_PATH||path.join('..', 'nm3clol-public')).replaceAll('\\', path.sep).replaceAll('/', path.sep)); @@ -223,16 +226,16 @@ export const getViewsPath = () => path.join(__dirname, '..', '..', 'dist', 'view export const getSolrDocsHost = () => env.SOLR_DOCS_HOST||'solr'; export const getSolrDocsPort = () => parseInt(env.SOLR_DOCS_PORT||'8983'); export const getSolrDocsCore = () => env.SOLR_DOCS_CORE||'nm3clol_core'; -export const getSolrDocsUrl = () => env.SOLR_DOCS_URL||`http://${getSolrDocsHost()}:${getSolrDocsPort()}/solr/${getSolrDocsCore()}`; +export const getSolrDocsUrl = () => trimSlashes(env.SOLR_DOCS_URL||`http://${getSolrDocsHost()}:${getSolrDocsPort()}/solr/${getSolrDocsCore()}`); export const getSolrLawHost = () => env.SOLR_LAW_HOST||getSolrDocsHost(); export const getSolrLawPort = () => env.SOLR_LAW_PORT ? parseInt(env.SOLR_LAW_PORT) : getSolrDocsPort(); export const getSolrLawCore = () => env.SOLR_LAW_CORE||'vacode_core'; -export const getSolrLawUrl = () => env.SOLR_LAW_URL||`http://${getSolrLawHost()}:${getSolrLawPort()}/solr/${getSolrLawCore()}`; +export const getSolrLawUrl = () => trimSlashes(env.SOLR_LAW_URL||`http://${getSolrLawHost()}:${getSolrLawPort()}/solr/${getSolrLawCore()}`); export const getTikaHost = () => env.TIKA_HOST||'tika'; export const getTikaPort = () => parseInt(env.TIKA_PORT||'9998'); -export const getTikaUrl = () => env.TIKA_URL||`http://${getTikaHost()}:${getTikaPort()}`; +export const getTikaUrl = () => trimSlashes(env.TIKA_URL||`http://${getTikaHost()}:${getTikaPort()}`); export const config: Config = { appHttpHost: getAppHttpHost(),