nm3clol-express-app/app/config.mts

269 lines
9.4 KiB
TypeScript

/**
* The `ProcessEnv` interface represents the imported environment variables to input from `process.env` dictionary.
*/
export interface ProcessEnv {
/**
* `APP_HTTP_LISTEN_HOST` is the host for the HTTP web app.
*/
APP_HTTP_HOST?: string;
/**
* `APP_HTTP_LISTEN_PORT` is the TCP port used to access the Node application's HTTP interface (usually by a reverse proxy).
*/
APP_HTTP_PORT?: string;
/**
* `APP_URL` is the URL used to access the Node application (usually by a reverse proxy).
*/
APP_HTTP_URL?: string;
/**
* `SITE_NAME` is used for page generation.
*/
SITE_NAME?: string;
/**
* `SITE_HOST` is used for generating links for the search index. (If you leave this blank it should work using relative paths.)
*/
SITE_WELCOME_MESSAGE?: string;
/**
* `SITE_URL` is used for generating links for the search index. (If you leave this blank it should work using relative paths.)
*/
SITE_HOST?: string;
/**
* `WELCOME_MESSAGE` is used for the homepage instead of `"Welcome to ${SITE_NAME}!"`
*/
SITE_URL?: string;
/**
* `PUBLIC_PATH` is the relative path to the directory to this project root for the public files.
*/
PUBLIC_PATH?: string;
/**
* `PAGES_PATH` is the relative path to the directory to this project root for the pages rather than public files.
*/
PAGES_PATH?: string;
/**
* `ASSETS_PATH` is the relative path to the directory to this project root for the static asset files.
*/
ASSETS_PATH?: string;
/**
* `SOLR_DOCS_HOST` is the host for Apache Solr's core for indexed documents.
*/
SOLR_DOCS_HOST?: string;
/**
* `SOLR_DOCS_PORT` is the port for Apache Solr's core for indexed documents.
*/
SOLR_DOCS_PORT?: string;
/**
* `SOLR_DOCS_CORE` is the core name for Apache Solr's core for indexed documents.
*/
SOLR_DOCS_CORE?: string;
/**
* `SOLR_DOCS_URL` is the URL to access Apache Solr's core for indexed documents. It is used by Gulp and the Search feature.
*/
SOLR_DOCS_URL?: string;
/**
* `SOLR_LAW_HOST` is the host for Apache Solr's core for indexed laws.
*/
SOLR_LAW_HOST?: string;
/**
* `SOLR_LAW_PORT` is the port for Apache Solr's core for indexed laws.
*/
SOLR_LAW_PORT?: string;
/**
* `SOLR_LAW_CORE` is the core name for Apache Solr's core for indexed laws.
*/
SOLR_LAW_CORE?: string;
/**
* `SOLR_LAW_URL` is the URL to access Apache Solr's core for indexed laws. It is used by Gulp and the Search feature.
*/
SOLR_LAW_URL?: string;
/**
* `TIKA_HOST` is the host to access the Apache Tika app.
*/
TIKA_HOST?: string;
/**
* `TIKA_PORT` is the port to access the Apache Tika app.
*/
TIKA_PORT?: string;
/**
* `TIKA_URL` is the URL to access the Apache Tika app.
*/
TIKA_URL?: string;
}
/**
* The `Config` interface represents the imported environment variables after imported from `process.env` dictionary.
*/
export interface Config {
/**
* `appHttpHost` is the host for the HTTP web app.
*/
appHttpHost: string;
/**
* `appHttpPort` is the TCP port used to access the Node application's HTTP interface (usually by a reverse proxy).
*/
appHttpPort: number|string;
/**
* `appHttpUrl` is the URL used to access the Node application (usually by a reverse proxy).
*/
appHttpUrl: string;
/**
* `siteName` is used for page generation.
*/
siteName: string;
/**
* `siteWelcomeMessage` is used for the homepage instead of `"Welcome to ${process.env['SITE_NAME']}!"`
*/
siteWelcomeMessage: string;
/**
* `siteHost` is used for generating links for the search index. (If you leave this blank it should work using relative paths.)
*/
siteHost: string;
/**
* `siteUrl` is used for generating links for the search index. (If you leave this blank it should work using relative paths.)
*/
siteUrl: string;
/**
* `publicPath` is the relative path to the directory to this project root for the public files.
*/
publicPath: string;
/**
* `pagesPath` is the relative path to the directory to this project root for the pages rather than public files.
*/
pagesPath: string;
/**
* `assetsPath` is the relative path to the directory to this project root for the static asset files.
*/
assetsPath: string;
/**
* `viewsPath' is the relative path to the directory to this project root for the view templates.
*/
viewsPath: string;
/**
* `solrDocsHost` is the host for Apache Solr's core for indexed documents.
*/
solrDocsHost: string;
/**
* `solrDocsPort` is the port for Apache Solr's core for indexed documents.
*/
solrDocsPort: number|string;
/**
* `solrDocsCore` is the core name for Apache Solr's core for indexed documents.
*/
solrDocsCore: string;
/**
* `solrDocsUrl` is the URL to access Apache Solr's core for indexed documents. It is used by Gulp and the Search feature.
*/
solrDocsUrl: string;
/**
* `solrLawHost` is the host for Apache Solr's core for indexed laws.
*/
solrLawHost: string;
/**
* `solrLawPort` is the port for Apache Solr's core for indexed laws.
*/
solrLawPort: number|string;
/**
* `solrLawCore` is the core name for Apache Solr's core for indexed laws.
*/
solrLawCore: string;
/**
* `solrLawUrl` is the URL to access Apache Solr's core for indexed laws. It is used by Gulp and the Search feature.
*/
solrLawUrl: string;
/**
* `tikaHost` is the host to access the Apache Tika app.
*/
tikaHost: string;
/**
* `tikaPort` is the port to access the Apache Tika app.
*/
tikaPort: string|number;
/**
* `tikaUrl` is the URL to access the Apache Tika app.
*/
tikaUrl: string;
}
import path from 'path';
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);
const env: ProcessEnv = {};
let dotEnvConfig = dotenv.config({
path: path.join(__dirname, '.env'),
processEnv: dotenv.config({
path: path.join(__dirname, '..', '..', '.env'),
processEnv: env as dotenv.DotenvPopulateInput}) as dotenv.DotenvPopulateInput
});
dotEnvConfig = dotenvExpand.expand({
parsed: env as dotenvExpand.DotenvParseInput,
processEnv: process.env as dotenvExpand.DotenvParseInput
});
export const getAppHttpHost = () => env.APP_HTTP_HOST||'nm3clol-express-app';
export const getAppHttpPort = () => process.env.PORT||env.APP_HTTP_PORT||3000;
export const getAppHttpUrl = () => {
return env.APP_HTTP_URL || `http://${getAppHttpHost() + ((getAppHttpPort() == '80') ? '' : ':' + getAppHttpPort())}`
};
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 = () => 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));
export const getPagesPath = () => path.join(__dirname, '..', '..', 'dist', (env.PAGES_PATH||'pages').replaceAll('\\', path.sep).replaceAll('/', path.sep));
export const getAssetsPath = () => path.join(__dirname, '..', '..', 'dist', (env.ASSETS_PATH||'assets').replaceAll('\\', path.sep).replaceAll('/', path.sep));
export const getViewsPath = () => path.join(__dirname, '..', '..', 'dist', 'views');
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 = () => 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 = () => 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 = () => trimSlashes(env.TIKA_URL||`http://${getTikaHost()}:${getTikaPort()}`);
export const config: Config = {
appHttpHost: getAppHttpHost(),
appHttpPort: getAppHttpPort(),
appHttpUrl: getAppHttpUrl(),
siteName: getSiteName(),
siteWelcomeMessage: getSiteWelcomeMessage(),
siteHost: getSiteHost(),
siteUrl: getSiteUrl(),
publicPath: getPublicPath(),
pagesPath: getPagesPath(),
assetsPath: getAssetsPath(),
viewsPath: getViewsPath(),
solrDocsHost: getSolrDocsHost(),
solrDocsPort: getSolrDocsPort(),
solrDocsCore: getSolrDocsCore(),
solrDocsUrl: getSolrDocsUrl(),
solrLawHost: getSolrLawHost(),
solrLawPort: getSolrLawPort(),
solrLawCore: getSolrLawCore(),
solrLawUrl: getSolrLawCore(),
tikaHost: getTikaHost(),
tikaPort: getTikaPort(),
tikaUrl: getTikaUrl(),
};