修改常见默认端口
This commit is contained in:
+8
-3
@@ -1,14 +1,19 @@
|
||||
PORT=8080
|
||||
# 端口(默认值已避开常见端口,避免与其他项目冲突;如需调整可在此覆盖)
|
||||
PORT=18080
|
||||
FRONTEND_PORT=15173
|
||||
# Caddy 对外端口:生产部署需域名绑定 80/443;本机与其他站点共存时可覆盖
|
||||
# HTTP_PORT=80
|
||||
# HTTPS_PORT=443
|
||||
JWT_SECRET=your_very_secure_jwt_secret_here_change_me_in_production
|
||||
DATA_ENCRYPTION_KEY=your_32_plus_char_data_encryption_key_change_me
|
||||
POSTGRES_USER=affiliate
|
||||
POSTGRES_PASSWORD=affiliate_dev_password
|
||||
POSTGRES_DB=affiliate_dash
|
||||
POSTGRES_PORT=5432
|
||||
POSTGRES_PORT=15432
|
||||
COMPOSE_PROJECT_NAME=affiliate_dash
|
||||
POSTGRES_DATA_VOLUME=affiliate_dash_postgres_data
|
||||
TZ=Asia/Shanghai
|
||||
DATABASE_URL="postgres://affiliate:affiliate_dev_password@127.0.0.1:5432/affiliate_dash?sslmode=disable&TimeZone=Asia/Shanghai"
|
||||
DATABASE_URL="postgres://affiliate:affiliate_dev_password@127.0.0.1:15432/affiliate_dash?sslmode=disable&TimeZone=Asia/Shanghai"
|
||||
# Docker 后端容器内连接串通常不需要改;需要外部数据库时再覆盖。
|
||||
# DOCKER_DATABASE_URL="postgres://affiliate:affiliate_dev_password@postgres:5432/affiliate_dash?sslmode=disable&TimeZone=Asia/Shanghai"
|
||||
GIN_MODE=release
|
||||
|
||||
@@ -21,9 +21,10 @@ install:
|
||||
|
||||
# 停止占用默认端口的进程
|
||||
stop:
|
||||
@-lsof -tiTCP:8080 -sTCP:LISTEN | xargs kill 2>/dev/null || true
|
||||
@-lsof -tiTCP:5173 -sTCP:LISTEN | xargs kill 2>/dev/null || true
|
||||
@echo "已尝试停止 8080 / 5173 端口服务"
|
||||
@-lsof -tiTCP:18080 -sTCP:LISTEN | xargs kill 2>/dev/null || true
|
||||
@-lsof -tiTCP:15173 -sTCP:LISTEN | xargs kill 2>/dev/null || true
|
||||
@-lsof -tiTCP:15432 -sTCP:LISTEN | xargs kill 2>/dev/null || true
|
||||
@echo "已尝试停止 18080 / 15173 / 15432 端口服务"
|
||||
|
||||
# Docker 部署:宿主机只需要 Docker/Compose,前端与后端都在镜像内构建
|
||||
docker-build:
|
||||
|
||||
@@ -36,8 +36,8 @@ make dev
|
||||
`make dev` 会通过 Docker Compose 启动 `affiliate_dash/postgres`,后端和前端仍在宿主机运行,方便热更新。首次从旧版 `affiliate_dash_postgres_dev` 开发容器迁移时,脚本会停止旧容器并优先复用旧数据卷。
|
||||
|
||||
启动后:
|
||||
- 前端:`http://localhost:5173`
|
||||
- 后端:`http://localhost:8080`
|
||||
- 前端:`http://localhost:15173`
|
||||
- 后端:`http://localhost:18080`
|
||||
- 默认管理员:`admin` / `admin123`
|
||||
|
||||
按 `Ctrl+C` 停止所有服务。
|
||||
@@ -49,8 +49,8 @@ make dev
|
||||
make install
|
||||
|
||||
# 分别启动
|
||||
make backend # 后端 :8080
|
||||
make frontend # 前端 :5173
|
||||
make backend # 后端 :18080
|
||||
make frontend # 前端 :15173
|
||||
```
|
||||
|
||||
## Docker 生产部署
|
||||
@@ -78,10 +78,10 @@ make docker-up
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
服务端口:
|
||||
- `:80` — 前端页面 + API(Caddy 统一入口)
|
||||
- `:8080` — 后端 API(直接访问,调试用)
|
||||
- `:5432` — PostgreSQL(本地开发/调试用,可通过 `POSTGRES_PORT` 调整)
|
||||
服务端口(默认值已避开常见端口,避免与其他项目冲突;均可在 `.env` 中覆盖):
|
||||
- `:80` — 前端页面 + API(Caddy 统一入口,可通过 `HTTP_PORT`/`HTTPS_PORT` 调整)
|
||||
- `:18080` — 后端 API(直接访问,调试用,可通过 `PORT` 调整)
|
||||
- `:15432` — PostgreSQL(本地开发/调试用,可通过 `POSTGRES_PORT` 调整)
|
||||
|
||||
### 常用命令
|
||||
|
||||
@@ -99,11 +99,13 @@ make docker-down # 停止并移除
|
||||
|
||||
| 变量 | 说明 | 默认值 |
|
||||
|------|------|--------|
|
||||
| `PORT` | 后端端口 | `8080` |
|
||||
| `PORT` | 后端端口 | `18080` |
|
||||
| `FRONTEND_PORT` | 前端开发端口 | `15173` |
|
||||
| `HTTP_PORT` / `HTTPS_PORT` | Caddy 对外 HTTP/HTTPS 端口 | `80` / `443` |
|
||||
| `JWT_SECRET` | JWT 签名密钥 | 开发默认值 |
|
||||
| `DATABASE_URL` | PostgreSQL 连接串 | 本地开发默认值 |
|
||||
| `DOCKER_DATABASE_URL` | Docker 后端容器内 PostgreSQL 连接串,通常无需设置 | Compose 内置默认值 |
|
||||
| `POSTGRES_PORT` | PostgreSQL 映射到宿主机的端口 | `5432` |
|
||||
| `POSTGRES_PORT` | PostgreSQL 映射到宿主机的端口 | `15432` |
|
||||
| `COMPOSE_PROJECT_NAME` | Docker Compose 项目名 | `affiliate_dash` |
|
||||
| `POSTGRES_DATA_VOLUME` | PostgreSQL 数据卷名 | `affiliate_dash_postgres_data` |
|
||||
| `GIN_MODE` | Gin 运行模式 | `debug` |
|
||||
|
||||
@@ -60,9 +60,9 @@ func Load() *Config {
|
||||
// OPEN_API_DEBUG 优先;未设置时 debug 模式默认开启
|
||||
debugOpen := getEnvBool("OPEN_API_DEBUG", mode == "debug" || mode == "")
|
||||
return &Config{
|
||||
Port: getEnv("PORT", "8080"),
|
||||
Port: getEnv("PORT", "18080"),
|
||||
JWTSecret: getEnv("JWT_SECRET", "affiliate-dash-dev-secret-change-me"),
|
||||
DatabaseURL: getEnv("DATABASE_URL", "postgres://affiliate:affiliate_dev_password@127.0.0.1:5432/affiliate_dash?sslmode=disable&TimeZone=Asia/Shanghai"),
|
||||
DatabaseURL: getEnv("DATABASE_URL", "postgres://affiliate:affiliate_dev_password@127.0.0.1:15432/affiliate_dash?sslmode=disable&TimeZone=Asia/Shanghai"),
|
||||
Mode: mode,
|
||||
DataEncryptionKey: getEnv("DATA_ENCRYPTION_KEY", getEnv("JWT_SECRET", "affiliate-dash-dev-secret-change-me")),
|
||||
OpenAPIKey: getEnv("OPEN_API_KEY", "sk_source_dev_key_change_me"),
|
||||
|
||||
@@ -23,7 +23,7 @@ func New(t testing.TB, _ ...interface{}) *gorm.DB {
|
||||
dsn = os.Getenv("DATABASE_URL")
|
||||
}
|
||||
if dsn == "" {
|
||||
dsn = "postgres://affiliate:affiliate_dev_password@127.0.0.1:5432/affiliate_dash?sslmode=disable"
|
||||
dsn = "postgres://affiliate:affiliate_dev_password@127.0.0.1:15432/affiliate_dash?sslmode=disable"
|
||||
}
|
||||
|
||||
cfg := &gorm.Config{Logger: logger.Default.LogMode(logger.Silent)}
|
||||
|
||||
+4
-4
@@ -11,7 +11,7 @@ services:
|
||||
- PGTZ=${TZ:-Asia/Shanghai}
|
||||
command: ["postgres", "-c", "timezone=${TZ:-Asia/Shanghai}"]
|
||||
ports:
|
||||
- "${POSTGRES_PORT:-5432}:5432"
|
||||
- "${POSTGRES_PORT:-15432}:5432"
|
||||
volumes:
|
||||
- postgres-data:/var/lib/postgresql/data
|
||||
restart: unless-stopped
|
||||
@@ -35,7 +35,7 @@ services:
|
||||
# 以宿主用户身份运行,日志文件归属正确(宿主机 logs 目录需预先 chown)
|
||||
user: "${HOST_UID:-1000}:${HOST_GID:-1000}"
|
||||
ports:
|
||||
- "8080:8080"
|
||||
- "${BACKEND_PORT:-18080}:8080"
|
||||
environment:
|
||||
- PORT=8080
|
||||
- TZ=${TZ:-Asia/Shanghai}
|
||||
@@ -82,8 +82,8 @@ services:
|
||||
ALPINE_MIRROR: ${ALPINE_MIRROR:-https://mirrors.aliyun.com/alpine}
|
||||
image: affiliate-caddy:latest
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
- "${HTTP_PORT:-80}:80"
|
||||
- "${HTTPS_PORT:-443}:443"
|
||||
environment:
|
||||
- TZ=${TZ:-Asia/Shanghai}
|
||||
volumes:
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
启动代理到 8080
|
||||
启动代理到 18080
|
||||
|
||||
cloudflared tunnel run --url http://localhost:8080 mac-mini-tunnel
|
||||
cloudflared tunnel run --url http://localhost:18080 mac-mini-tunnel
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# 复制为 frontend/.env 后生效(Vite 仅暴露 VITE_ 前缀变量)
|
||||
|
||||
# 开发服务器端口(也可由根目录 FRONTEND_PORT 通过 start.sh 传入)
|
||||
# PORT=5173
|
||||
# PORT=15173
|
||||
|
||||
# 后端 API 代理目标(见 vite.config.ts)
|
||||
VITE_API_PROXY_TARGET=http://localhost:8080
|
||||
VITE_API_PROXY_TARGET=http://localhost:18080
|
||||
|
||||
@@ -15,8 +15,8 @@ const { Paragraph, Text } = Typography
|
||||
|
||||
const baseUrl =
|
||||
typeof window !== 'undefined'
|
||||
? window.location.origin.replace(':5173', ':8080')
|
||||
: 'http://localhost:8080'
|
||||
? window.location.origin.replace(':15173', ':18080')
|
||||
: 'http://localhost:18080'
|
||||
|
||||
const deliveryModes = [
|
||||
{
|
||||
|
||||
@@ -4,8 +4,8 @@ import react from '@vitejs/plugin-react'
|
||||
export default defineConfig(({ mode }) => {
|
||||
// 读取 frontend/.env* 与进程环境(start.sh 会注入根目录 .env)
|
||||
const env = loadEnv(mode, process.cwd(), '')
|
||||
const apiTarget = env.VITE_API_PROXY_TARGET || 'http://localhost:8080'
|
||||
const port = Number(env.PORT || env.FRONTEND_PORT || 5173)
|
||||
const apiTarget = env.VITE_API_PROXY_TARGET || 'http://localhost:18080'
|
||||
const port = Number(env.PORT || env.FRONTEND_PORT || 15173)
|
||||
|
||||
return {
|
||||
plugins: [react()],
|
||||
|
||||
@@ -18,18 +18,22 @@ elif [[ -f "$ROOT/.env.example" ]]; then
|
||||
log "未找到 .env,可执行: cp .env.example .env"
|
||||
fi
|
||||
|
||||
BACKEND_PORT="${PORT:-8080}"
|
||||
FRONTEND_PORT="${FRONTEND_PORT:-5173}"
|
||||
BACKEND_PORT="${PORT:-18080}"
|
||||
FRONTEND_PORT="${FRONTEND_PORT:-15173}"
|
||||
POSTGRES_USER="${POSTGRES_USER:-affiliate}"
|
||||
POSTGRES_PASSWORD="${POSTGRES_PASSWORD:-affiliate_dev_password}"
|
||||
POSTGRES_DB="${POSTGRES_DB:-affiliate_dash}"
|
||||
POSTGRES_PORT="${POSTGRES_PORT:-5432}"
|
||||
POSTGRES_PORT="${POSTGRES_PORT:-15432}"
|
||||
POSTGRES_IMAGE="${POSTGRES_IMAGE:-docker.m.daocloud.io/library/postgres:16-alpine}"
|
||||
COMPOSE_PROJECT_NAME="${COMPOSE_PROJECT_NAME:-affiliate_dash}"
|
||||
POSTGRES_DATA_VOLUME="${POSTGRES_DATA_VOLUME:-affiliate_dash_postgres_data}"
|
||||
LEGACY_DEV_DB_CONTAINER="${DEV_DB_CONTAINER:-affiliate_dash_postgres_dev}"
|
||||
TZ="${TZ:-Asia/Shanghai}"
|
||||
DATABASE_URL="${DATABASE_URL:-postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@127.0.0.1:${POSTGRES_PORT}/${POSTGRES_DB}?sslmode=disable&TimeZone=${TZ}}"
|
||||
# 兼容旧 .env:本地 DATABASE_URL 端口与 POSTGRES_PORT 不一致时提醒
|
||||
if [[ "${DATABASE_URL}" == *"127.0.0.1:"* ]] && [[ "${DATABASE_URL}" != *"127.0.0.1:${POSTGRES_PORT}/"* ]]; then
|
||||
log "警告: .env 中 DATABASE_URL 的本地端口与 POSTGRES_PORT(${POSTGRES_PORT}) 不一致,请更新 .env"
|
||||
fi
|
||||
export DATABASE_URL
|
||||
export TZ
|
||||
export COMPOSE_PROJECT_NAME
|
||||
|
||||
Reference in New Issue
Block a user