From d2e93073f81d83cada29b3a9527c221dcd7e95c3 Mon Sep 17 00:00:00 2001 From: david_bai Date: Mon, 30 Jun 2025 20:45:06 +0800 Subject: [PATCH] replace .env.development[production].local with .env.development[production];add env example --- .gitignore | 3 --- README.md | 4 ++-- README.zh-CN.md | 4 ++-- backend/.env_development_example | 6 ++++++ backend/.env_production_example | 18 ++++++++++++++++++ backend/README.md | 2 +- backend/README.zh-CN.md | 2 +- backend/docker/Nginx/renew_ssl.sh | 2 +- backend/src/config/env.ts | 4 ++-- docs/DEPLOYMENT.md | 14 +++++++------- docs/DEPLOYMENT.zh-CN.md | 18 +++++++++--------- frontend/.env_development_example | 1 + frontend/.env_production_example | 5 +++++ frontend/README.md | 2 +- frontend/README.zh-CN.md | 2 +- 15 files changed, 57 insertions(+), 30 deletions(-) create mode 100644 backend/.env_development_example create mode 100644 backend/.env_production_example create mode 100755 frontend/.env_development_example create mode 100644 frontend/.env_production_example diff --git a/.gitignore b/.gitignore index cfbfc87..6c0a98f 100644 --- a/.gitignore +++ b/.gitignore @@ -30,9 +30,6 @@ npm-debug.log* yarn-debug.log* yarn-error.log* -# local env files -.env*.local - # vercel .vercel diff --git a/README.md b/README.md index d000238..94df424 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Before you begin, ensure your development environment has [Node.js](https://node cd backend npm install - # Create and configure .env.development.local according to the instructions in backend/README.md + # Create and configure .env.development according to the instructions in backend/README.md npm run dev # Starts by default at http://localhost:3001 ``` @@ -62,7 +62,7 @@ Before you begin, ensure your development environment has [Node.js](https://node cd frontend pnpm install - # Create and configure .env.development.local according to the instructions in frontend/README.md + # Create and configure .env.development according to the instructions in frontend/README.md pnpm dev # Starts by default at http://localhost:3002 ``` diff --git a/README.zh-CN.md b/README.zh-CN.md index 3387c4b..7a7f134 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -51,7 +51,7 @@ PrivyDrop (原 SecureShare) 是一个基于 WebRTC 的开源点对点(P2P) cd backend npm install - # 根据 backend/README.zh-CN.md 指引创建并配置 .env.development.local + # 根据 backend/README.zh-CN.md 指引创建并配置 .env.development npm run dev # 默认启动于 http://localhost:3001 ``` @@ -62,7 +62,7 @@ PrivyDrop (原 SecureShare) 是一个基于 WebRTC 的开源点对点(P2P) cd frontend pnpm install - # 根据 frontend/README.zh-CN.md 指引创建并配置 .env.development.local + # 根据 frontend/README.zh-CN.md 指引创建并配置 .env.development pnpm dev # 默认启动于 http://localhost:3002 ``` diff --git a/backend/.env_development_example b/backend/.env_development_example new file mode 100644 index 0000000..d3e4d77 --- /dev/null +++ b/backend/.env_development_example @@ -0,0 +1,6 @@ +BACKEND_PORT=3001 + +REDIS_HOST='localhost' +REDIS_PORT=6379 + +CORS_ORIGIN=http://localhost:3002 \ No newline at end of file diff --git a/backend/.env_production_example b/backend/.env_production_example new file mode 100644 index 0000000..8146940 --- /dev/null +++ b/backend/.env_production_example @@ -0,0 +1,18 @@ +BACKEND_PORT=3001 + +REDIS_HOST='localhost' +REDIS_PORT=6379 + +CORS_ORIGIN=https://www.privydrop.app + +# TURN Server Configuration +TURN_EXTERNAL_IP=43.153.3.146 +TURN_REALM=turn.privydrop.app +TURN_USERNAME=[Username] +TURN_PASSWORD=[Password] +TURN_CERT_PATH=/etc/letsencrypt/live/privydrop.app/fullchain.pem +TURN_KEY_PATH=/etc/letsencrypt/live/privydrop.app/privkey.pem + +# Nginx Configuration +NGINX_SERVER_NAME=privydrop.app +NGINX_FRONTEND_ROOT=[path/to/your/PrivyDrop/frontend] \ No newline at end of file diff --git a/backend/README.md b/backend/README.md index 86f7f27..812a7a8 100644 --- a/backend/README.md +++ b/backend/README.md @@ -33,7 +33,7 @@ This is the backend server for PrivyDrop. It is built with Node.js, Express, and ``` 3. **Configure Environment Variables** - Create a `.env.development.local` file in the `backend/` directory and populate it with the following variables: + Create a `.env.development` file in the `backend/` directory and populate it with the following variables: ```ini # Server Configuration diff --git a/backend/README.zh-CN.md b/backend/README.zh-CN.md index 1f37496..627b469 100644 --- a/backend/README.zh-CN.md +++ b/backend/README.zh-CN.md @@ -33,7 +33,7 @@ ``` 3. **配置环境变量** - 在 `backend/` 目录中创建一个 `.env.development.local` 文件,并填充以下变量: + 在 `backend/` 目录中创建一个 `.env.development` 文件,并填充以下变量: ```ini # 服务器配置 diff --git a/backend/docker/Nginx/renew_ssl.sh b/backend/docker/Nginx/renew_ssl.sh index 2a95a22..3ce276e 100755 --- a/backend/docker/Nginx/renew_ssl.sh +++ b/backend/docker/Nginx/renew_ssl.sh @@ -39,6 +39,6 @@ for CERT_PATH in "$CERTBOT_DIR"/*/fullchain.pem; do echo "Failed to renew certificate for $DOMAIN" fi # Start nginx - sudo bash configure.sh ../../.env.production.local + sudo bash configure.sh ../../.env.production fi done \ No newline at end of file diff --git a/backend/src/config/env.ts b/backend/src/config/env.ts index 8868b73..ca16ac7 100644 --- a/backend/src/config/env.ts +++ b/backend/src/config/env.ts @@ -16,8 +16,8 @@ interface AppConfig { dotenv.config({ path: process.env.NODE_ENV === "production" - ? path.resolve(process.cwd(), ".env.production.local") - : path.resolve(process.cwd(), ".env.development.local"), + ? path.resolve(process.cwd(), ".env.production") + : path.resolve(process.cwd(), ".env.development"), }); // Check for necessary Redis environment variables if (!process.env.REDIS_HOST) { diff --git a/docs/DEPLOYMENT.md b/docs/DEPLOYMENT.md index d50b7a6..90c1830 100644 --- a/docs/DEPLOYMENT.md +++ b/docs/DEPLOYMENT.md @@ -112,8 +112,8 @@ sudo apt install coturn ```bash # Located in the backend/ directory - sudo bash ./docker/TURN/configure.sh path/to/your/.env.production.local - # For a development environment, use .env.development.local + sudo bash ./docker/TURN/configure.sh path/to/your/.env.production + # For a development environment, use .env.development sudo systemctl status coturn ``` @@ -179,7 +179,7 @@ In production, Nginx will act as the entry point for all traffic, handling SSL t 4. **Nginx Configuration File:** The `backend/docker/Nginx/` directory in the project provides a configuration script and template. - - Add the `NGINX_*` related variables to your backend's `.env.production.local` file, including the domain, certificate paths, and the **root directory of the frontend build artifacts**. Example: + - Add the `NGINX_*` related variables to your backend's `.env.production` file, including the domain, certificate paths, and the **root directory of the frontend build artifacts**. Example: ``` NGINX_SERVER_NAME=yourdomain.com # The full domain name @@ -191,17 +191,17 @@ In production, Nginx will act as the entry point for all traffic, handling SSL t 5. **Apply Configuration:** Generate the Nginx config, create a symbolic link, and restart Nginx. ```bash # This script uses NGINX_* variables from your .env file to generate the Nginx config - sudo bash backend/docker/Nginx/configure.sh backend/.env.production.local + sudo bash backend/docker/Nginx/configure.sh backend/.env.production ``` ### 4.4. Configure Environment Variables - **Backend:** - - Create a `.env.production.local` file in the `backend/` directory. + - Create a `.env.production` file in the `backend/` directory. - Fill in the necessary environment variables (e.g., `BACKEND_PORT`, `REDIS_HOST`, `REDIS_PORT`, `CORS_ORIGIN`). - For Nginx integration, also add `NGINX_SERVER_NAME`, `NGINX_SSL_CERT`, `NGINX_SSL_KEY`, and `NGINX_FRONTEND_ROOT`. - **Frontend:** - - Create a `.env.production.local` file in the `frontend/` directory. + - Create a `.env.production` file in the `frontend/` directory. - Fill in the `NEXT_PUBLIC_API_URL` variable. ### 4.5. Run the Application with PM2 @@ -219,7 +219,7 @@ PM2 is a powerful process manager for Node.js. We will use it to run the backend ```bash cd backend - # Ensure .env.production.local is fully configured + # Ensure .env.production is fully configured pm2 start ecosystem.config.js ``` diff --git a/docs/DEPLOYMENT.zh-CN.md b/docs/DEPLOYMENT.zh-CN.md index 38bfe3c..e85b0ef 100644 --- a/docs/DEPLOYMENT.zh-CN.md +++ b/docs/DEPLOYMENT.zh-CN.md @@ -112,8 +112,8 @@ sudo apt install coturn ```bash # 位于 backend/ 目录 - sudo bash ./docker/TURN/configure.sh path/to/your/.env.production.local - # 开发环境使用 .env.development.local + sudo bash ./docker/TURN/configure.sh path/to/your/.env.production + # 开发环境使用 .env.development sudo systemctl status coturn ``` @@ -179,7 +179,7 @@ cd backend && npm build && cd .. 4. **Nginx 配置文件:** 后端项目 `backend/docker/Nginx/` 目录中提供了配置脚本和模板。 - - 在后端的 `.env.production.local` 文件中添加 `NGINX_*` 相关变量,包括域名、证书路径和**前端构建产物的根目录**,示例为: + - 在后端的 `.env.production` 文件中添加 `NGINX_*` 相关变量,包括域名、证书路径和**前端构建产物的根目录**,示例为: ``` NGINX_SERVER_NAME=yourdomain # 不带 www 前缀,yourdomain包含了后缀 @@ -190,16 +190,16 @@ cd backend && npm build && cd .. 5. **应用配置:** 创建软链接并重启 Nginx。 ```bash - # 此脚本会使用 .env.production.local 中的 NGINX_* 变量来生成 Nginx 配置文件 - sudo bash docker/Nginx/configure.sh .env.production.local + # 此脚本会使用 .env.production 中的 NGINX_* 变量来生成 Nginx 配置文件 + sudo bash docker/Nginx/configure.sh .env.production ``` ### 4.4. 配置环境变量 - **后端:** - - 在 `backend/` 目录下创建 `.env.production.local` 或 `.env.development.local` 文件 - - 在 `.env.development.local` 文件中填入环境变量 (BACKEND_PORT, REDIS_HOST, REDIS_PORT, CORS_ORIGIN)。 - - 在 `.env.production.local` 文件中除了上述变量外,还要加入 (NGINX_SERVER_NAME, NGINX_SSL_CERT, NGINX_SSL_KEY, NGINX_FRONTEND_ROOT)。 + - 在 `backend/` 目录下创建 `.env.production` 或 `.env.development` 文件 + - 在 `.env.development` 文件中填入环境变量 (BACKEND_PORT, REDIS_HOST, REDIS_PORT, CORS_ORIGIN)。 + - 在 `.env.production` 文件中除了上述变量外,还要加入 (NGINX_SERVER_NAME, NGINX_SSL_CERT, NGINX_SSL_KEY, NGINX_FRONTEND_ROOT)。 - **前端:** 在 `frontend/` 目录下创建 `.env.production` 或 `.env.development` 文件,并填入环境变量 (NEXT_PUBLIC_API_URL)。 ### 4.5. 使用 PM2 运行应用 @@ -217,7 +217,7 @@ PM2 是一个强大的 Node.js 进程管理器,我们将用它来分别运行 ```bash cd backend - # 确保 .env.production.local 已配置完毕 + # 确保 .env.production 已配置完毕 pm2 start ecosystem.config.js ``` diff --git a/frontend/.env_development_example b/frontend/.env_development_example new file mode 100755 index 0000000..061df71 --- /dev/null +++ b/frontend/.env_development_example @@ -0,0 +1 @@ +NEXT_PUBLIC_API_URL=http://43.142.81.156:3001 \ No newline at end of file diff --git a/frontend/.env_production_example b/frontend/.env_production_example new file mode 100644 index 0000000..744c31f --- /dev/null +++ b/frontend/.env_production_example @@ -0,0 +1,5 @@ +NEXT_PUBLIC_API_URL=https://www.privydrop.app + +NEXT_PUBLIC_TURN_HOST=turn.privydrop.app +NEXT_PUBLIC_TURN_USERNAME=[Username] +NEXT_PUBLIC_TURN_PASSWORD=[Password] \ No newline at end of file diff --git a/frontend/README.md b/frontend/README.md index 602e46d..0fa9ad7 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -25,7 +25,7 @@ Before you start, please ensure you have **installed and started the backend ser pnpm install ``` 3. **Configure Environment Variables** - Create a `.env.development.local` file in the `frontend/` directory and add the necessary environment variables for development. At a minimum, you need to specify the backend API address: + Create a `.env.development` file in the `frontend/` directory and add the necessary environment variables for development. At a minimum, you need to specify the backend API address: ```ini NEXT_PUBLIC_API_URL=http://localhost:3001 ``` diff --git a/frontend/README.zh-CN.md b/frontend/README.zh-CN.md index f385ef3..9b88d9b 100644 --- a/frontend/README.zh-CN.md +++ b/frontend/README.zh-CN.md @@ -25,7 +25,7 @@ pnpm install ``` 3. **配置环境变量** - 在 `frontend/` 目录下创建 `.env.development.local` 文件,并填入开发所需的环境变量,至少需要指定后端 API 的地址: + 在 `frontend/` 目录下创建 `.env.development` 文件,并填入开发所需的环境变量,至少需要指定后端 API 的地址: ```ini NEXT_PUBLIC_API_URL=http://localhost:3001 ```