104 lines
4.6 KiB
TypeScript
104 lines
4.6 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 {
|
|
// AMAZON_PA_ACCESS_KEY?: string;
|
|
// AMAZON_PA_SECRET_KEY?: string;
|
|
// AMAZON_PA_HOST?: string;
|
|
// AMAZON_PA_REGION?: string;
|
|
// AMAZON_PA_PARTNER_TYPE?: string;
|
|
// AMAZON_PA_PARTNER_TAG?: string;
|
|
// GOOGLE_ADSENSE_ADS_TXT?: string;
|
|
// GOOGLE_ANALYTICS_GTAG?: string;
|
|
SITE_URL?: string;
|
|
STRAPI_URL?: string;
|
|
STRAPI_API_TOKEN?: string;
|
|
PORT?: string;
|
|
WEBHOOK_PORT?: string;
|
|
SQUIDEX_APP_NAME?: string;
|
|
SQUIDEX_CLIENT_ID?: string;
|
|
SQUIDEX_CLIENT_SECRET?: string;
|
|
SQUIDEX_ENVIRONMENT?: string;
|
|
SQUIDEX_PUBLIC_URL?: string;
|
|
}
|
|
|
|
export interface Config {
|
|
// AmazonProductAdvertisingAPIAccessKey: string;
|
|
// AmazonProductAdvertisingAPISecretKey: string;
|
|
// AmazonProductAdvertisingAPIHost: string;
|
|
// AmazonProductAdvertisingAPIRegion: string;
|
|
// AmazonProductAdvertisingAPIPartnerType: string;
|
|
// AmazonProductAdvertisingAPIPartnerTag: string;
|
|
// GoogleAdsenseAdsTxt: string;
|
|
// GoogleAnalyticsGTag: string;
|
|
siteUrl: string;
|
|
strapiUrl: string;
|
|
strapiApiToken: string;
|
|
port: number;
|
|
webhookPort: number;
|
|
squidexAppName?: string;
|
|
squidexClientId?: string;
|
|
squidexClientSecret?: string;
|
|
squidexEnvironment?: string;
|
|
squidexPublicUrl?: 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 getAmazonProductAdvertisingAPIAccessKey = () => (env.AMAZON_PA_ACCESS_KEY||``).trim();
|
|
// export const getAmazonProductAdvertisingAPISecretKey = () => (env.AMAZON_PA_SECRET_KEY||``).trim();
|
|
// export const getAmazonProductAdvertisingAPIHost = () => (env.AMAZON_PA_HOST||``).trim();
|
|
// export const getAmazonProductAdvertisingAPIRegion = () => (env.AMAZON_PA_REGION||``).trim();
|
|
// export const getAmazonProductAdvertisingAPIPartnerType = () => (env.AMAZON_PA_PARTNER_TYPE||`Associate`).trim();
|
|
// export const getAmazonProductAdvertisingAPIPartnerTag = () => (env.AMAZON_PA_PARTNER_TAG||``).trim();
|
|
// 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 getStrapiUrl = () => trimSlashes(env.STRAPI_URL||`http://localhost:1337`);
|
|
export const getStrapiApiToken = () => trimSlashes(env.STRAPI_API_TOKEN!);
|
|
export const getPort = () => env.PORT ? parseInt(env.PORT!) : 4321;
|
|
export const getWebhookPort = () => env.WEBHOOK_PORT ? parseInt(env.WEBHOOK_PORT!) : 3210;
|
|
export const getSquidexAppName = () => env.SQUIDEX_APP_NAME || undefined;
|
|
export const getSquidexClientId = () => env.SQUIDEX_CLIENT_ID || undefined;
|
|
export const getSquidexClientSecret = () => env.SQUIDEX_CLIENT_SECRET || undefined;
|
|
export const getSquidexEnvironment = () => trimSlashes(env.SQUIDEX_ENVIRONMENT||'') || undefined;
|
|
export const getSquidexPublicUrl = () => trimSlashes(env.SQUIDEX_PUBLIC_URL||'') || getSquidexEnvironment();
|
|
|
|
export const config: Config = {
|
|
// AmazonProductAdvertisingAPIAccessKey: getAmazonProductAdvertisingAPIAccessKey(),
|
|
// AmazonProductAdvertisingAPIHost: getAmazonProductAdvertisingAPIHost(),
|
|
// AmazonProductAdvertisingAPIPartnerTag: getAmazonProductAdvertisingAPIPartnerTag(),
|
|
// AmazonProductAdvertisingAPIPartnerType: getAmazonProductAdvertisingAPIPartnerType(),
|
|
// AmazonProductAdvertisingAPIRegion: getAmazonProductAdvertisingAPIRegion(),
|
|
// AmazonProductAdvertisingAPISecretKey: getAmazonProductAdvertisingAPISecretKey(),
|
|
// GoogleAnalyticsGTag: getGoogleAnalyticsGtag(),
|
|
// GoogleAdsenseAdsTxt: getGoogleAdsenseAdsTxt(),
|
|
siteUrl: getSiteUrl(),
|
|
strapiApiToken: getStrapiApiToken(),
|
|
strapiUrl: getStrapiUrl(),
|
|
port: getPort(),
|
|
webhookPort: getWebhookPort(),
|
|
squidexAppName: getSquidexAppName(),
|
|
squidexClientId: getSquidexClientId(),
|
|
squidexClientSecret: getSquidexClientSecret(),
|
|
squidexEnvironment: getSquidexEnvironment(),
|
|
squidexPublicUrl: getSquidexPublicUrl(),
|
|
};
|