dashersupply/src/config.ts

44 lines
1.4 KiB
TypeScript

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);
export interface ProcessEnv {
GOOGLE_ADSENSE_ADS_TXT?: string;
GOOGLE_ANALYTICS_GTAG?: string;
SITE_URL?: string;
}
export interface Config {
GoogleAdsenseAdsTxt: string;
GoogleAnalyticsGTag: string;
siteUrl: string;
}
const env: ProcessEnv = {};
let dotEnvConfig = dotenv.config({
path: path.resolve(process.cwd(), '.env'),
processEnv: env as dotenv.DotenvPopulateInput
});
dotEnvConfig = dotenvExpand.expand({
parsed: env as dotenvExpand.DotenvParseInput,
processEnv: process.env as dotenvExpand.DotenvParseInput
});
export const getGoogleAnalyticsGtag = () => (env.GOOGLE_ANALYTICS_GTAG||``).trim();
export const getGoogleAdsenseAdsTxt = () => (env.GOOGLE_ADSENSE_ADS_TXT||``).trim()||`google.com, pub-1234567890abcdef, DIRECT, fedcba9876543210`;
export const getSiteUrl = () => trimSlashes(env.SITE_URL||`http://localhost`);
export const config: Config = {
GoogleAnalyticsGTag: getGoogleAnalyticsGtag(),
GoogleAdsenseAdsTxt: getGoogleAdsenseAdsTxt(),
siteUrl: getSiteUrl(),
};