diff --git a/.env.example b/.env.example index c62f8f7..d32ca37 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,51 @@ +# Copypaste this files as .env and fill blanks + +# used to ensure this env files is loaded exactly one +ENV_FILE_LOADED=true + PORT=3012 # https://yandex.cloud/ru/docs/serverless-containers/quickstart/container#cli_1 REGISTRY_NAME="nezort11-registry" CONTAINER_NAME="serverless-curl-impersonate" SERVICE_ACCOUNT_ID="..." + +# CONTAINER_NUMBER="" + +# # https://github.com/FOSWLY/vot-cli/blob/main/src/config/config.js +# # EXPIRES AFTER SOME TIME +# YANDEX_TRANSLATE_HMAC_SHA254_SECRET="" + +# BOT_TOKEN_PROD="" +# BOT_TOKEN_DEV="" +# BOT_PUBLIC_USERNAME="" +# OWNER_USERNAME="" + +# APP_ID="" +# APP_HASH="" +# # npx tglogin +# SESSION_PROD="" +# SESSION_DEV="" + +# NOTIFICATION_BOT_TOKEN="" +# NOTIFICATION_USER_ID="" +# STORAGE_CHANNEL_CHAT_ID="" + +# SENTRY_DSN="" + +# IMAGE_TRANSLATE_URL="" + +# LOGGING_CHANNEL_ID="" + +# # REGISTRY_NAME="" +# # CONTAINER_NAME="" +# # IMAGE_NAME="" +# # SERVICE_ACCOUNT_ID="" +# # CONTAINER_DOMAIN="" + +# # UPLOADER_URL_PROD="http://telegram_upload:3000" +# # UPLOADER_URL_DEV="http://127.0.0.1:3000" + +# # SERVER_PASSWORD="" + + diff --git a/src/env.ts b/src/env.ts index 5f6aacf..8fc5ce3 100644 --- a/src/env.ts +++ b/src/env.ts @@ -1,16 +1,18 @@ import dotenv from "dotenv"; -export const DEBUG_ENV = process.env.DEBUG_ENV; -console.log("DEBUG_ENV", DEBUG_ENV); export const NODE_ENV = process.env.NODE_ENV; console.log("NODE_ENV", NODE_ENV); export const IS_PRODUCTION = process.env.NODE_ENV !== "development"; -// otherwise loaded directly by docker env/env_file -if (DEBUG_ENV) { +// ensure env is loaded once (prevent duplicate loading) +// otherwise loaded directly by docker env/env_file or serverless environment/etc. +if (!process.env.ENV_FILE_LOADED) { // const dotenv = await import("dotenv/lib/main"); // this produces ERROR cuz of dotenv package.json exports field // const dotenv = await import("dotenv"); // required ESNext module which breaks a lot dotenv.config({ path: "./.env" }); // mutates process.env from .env } +export const DEBUG_ENV = process.env.DEBUG_ENV === "true"; +console.log("DEBUG_ENV", DEBUG_ENV); + export const PORT = process.env.PORT; diff --git a/src/types/env.d.ts b/src/types/env.d.ts index 2be347e..2b1b4e5 100644 --- a/src/types/env.d.ts +++ b/src/types/env.d.ts @@ -3,8 +3,11 @@ export {}; declare global { namespace NodeJS { interface ProcessEnv { + ENV_FILE_LOADED: "true" | undefined; + NODE_ENV: "development" | "production"; - DEBUG: "true" | "false"; + DEBUG: "*"; + DEBUG_ENV: "true" | undefined; } } }