diff --git a/.env.example b/.env.example index 4c970d2..ad00665 100644 --- a/.env.example +++ b/.env.example @@ -7,10 +7,6 @@ POSTGRES_DB=ids_ecommerce POSTGRES_SCHEMA=product POSTGRES_SSLMODE=disable NATS_URL=nats://localhost:4222 -# Must match ids-svc-storage's public signing endpoint. It is used only when -# returning storage-relative images embedded in product detail_html. -S3_PUBLIC_ENDPOINT=http://localhost:9000 - METRICS_PORT=:9102 OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 OTEL_EXPORTER_OTLP_INSECURE=true diff --git a/README.md b/README.md index b3c9f52..7bb968b 100644 --- a/README.md +++ b/README.md @@ -250,7 +250,6 @@ cp .env.example .env | `POSTGRES_SCHEMA` | `product` | 搜索路径 | | `POSTGRES_SSLMODE` | `disable` | SSL 模式 | | `NATS_URL` | `nats://localhost:4222` | 预留事件总线地址(首版查询链路不依赖) | -| `S3_PUBLIC_ENDPOINT` | `http://localhost:9000` | 存储服务对外媒体域名;须与 `ids-svc-storage` 同值。商品详情返回时会用它补全 `/ids-storage/...` 图片地址。 | | `METRICS_PORT` | `:9102` | Prometheus 指标与 HTTP 健康检查监听地址 | | `OTEL_EXPORTER_OTLP_ENDPOINT` | `http://localhost:4318` | OTLP HTTP trace exporter 地址 | | `OTEL_EXPORTER_OTLP_INSECURE` | `true` | OTLP exporter 是否使用明文连接 | diff --git a/cmd/main.go b/cmd/main.go index 91e668a..f484455 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -86,9 +86,7 @@ func main() { } }() - productServer := server.NewProductServer(repo, idGenerator, logger, observer, - server.WithDetailHTMLAssetOrigin(cfg.S3PublicEndpoint), - ) + productServer := server.NewProductServer(repo, idGenerator, logger, observer) server.StartScheduledSaleWorker(ctx, repo, logger, time.Minute) grpcServer := grpc.NewServer( diff --git a/docker-compose.yaml b/docker-compose.yaml index a3df398..c65f107 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -16,7 +16,6 @@ services: POSTGRES_SCHEMA: ${POSTGRES_SCHEMA:-product} POSTGRES_SSLMODE: ${POSTGRES_SSLMODE:-disable} NATS_URL: nats://nats:4222 - S3_PUBLIC_ENDPOINT: ${S3_PUBLIC_ENDPOINT} METRICS_PORT: ":9102" OTEL_EXPORTER_OTLP_ENDPOINT: http://ids-tempo:4318 OTEL_EXPORTER_OTLP_INSECURE: "true" diff --git a/internal/config/config.go b/internal/config/config.go index c880502..ee32c3d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -5,24 +5,22 @@ import ( "fmt" "net/url" "os" - "strings" "github.com/joho/godotenv" ) const ( - defaultServerPort = ":50052" - defaultPostgresHost = "localhost" - defaultPostgresPort = "5432" - defaultPostgresUser = "postgres" - defaultPostgresPass = "postgres" - defaultPostgresDB = "ids_ecommerce" - defaultPostgresSchema = "product" - defaultNATSURL = "nats://localhost:4222" - defaultMetricsPort = ":9102" - defaultOTLPEndpoint = "http://localhost:4318" - defaultEnvironment = "development" - defaultS3PublicEndpoint = "http://localhost:9000" + defaultServerPort = ":50052" + defaultPostgresHost = "localhost" + defaultPostgresPort = "5432" + defaultPostgresUser = "postgres" + defaultPostgresPass = "postgres" + defaultPostgresDB = "ids_ecommerce" + defaultPostgresSchema = "product" + defaultNATSURL = "nats://localhost:4222" + defaultMetricsPort = ":9102" + defaultOTLPEndpoint = "http://localhost:4318" + defaultEnvironment = "development" ) // Config holds runtime configuration loaded from environment variables. @@ -34,9 +32,6 @@ type Config struct { OTLPEndpoint string OTELInsecure bool Environment string - // S3PublicEndpoint is the public media origin used when product rich-text - // contains a storage-relative image URL. It must match ids-svc-storage. - S3PublicEndpoint string } // LoadConfig loads .env when present and assembles configuration from environment variables. @@ -49,42 +44,17 @@ func LoadConfig() (*Config, error) { if err != nil { return nil, err } - s3PublicEndpoint, err := publicMediaOrigin(getEnv("S3_PUBLIC_ENDPOINT", defaultS3PublicEndpoint)) - if err != nil { - return nil, fmt.Errorf("invalid S3_PUBLIC_ENDPOINT: %w", err) - } - return &Config{ - ServerPort: getEnv("SERVER_PORT", defaultServerPort), - PostgresDSN: dsn, - NATSURL: getEnv("NATS_URL", defaultNATSURL), - MetricsPort: getEnv("METRICS_PORT", defaultMetricsPort), - OTLPEndpoint: getEnv("OTEL_EXPORTER_OTLP_ENDPOINT", defaultOTLPEndpoint), - OTELInsecure: getEnv("OTEL_EXPORTER_OTLP_INSECURE", "true") == "true", - Environment: getEnv("DEPLOYMENT_ENVIRONMENT", defaultEnvironment), - S3PublicEndpoint: s3PublicEndpoint, + ServerPort: getEnv("SERVER_PORT", defaultServerPort), + PostgresDSN: dsn, + NATSURL: getEnv("NATS_URL", defaultNATSURL), + MetricsPort: getEnv("METRICS_PORT", defaultMetricsPort), + OTLPEndpoint: getEnv("OTEL_EXPORTER_OTLP_ENDPOINT", defaultOTLPEndpoint), + OTELInsecure: getEnv("OTEL_EXPORTER_OTLP_INSECURE", "true") == "true", + Environment: getEnv("DEPLOYMENT_ENVIRONMENT", defaultEnvironment), }, nil } -// publicMediaOrigin accepts an absolute HTTP(S) origin only. Relative paths, -// credentials, queries and fragments make signed media URL rewriting ambiguous. -func publicMediaOrigin(raw string) (string, error) { - parsed, err := url.Parse(strings.TrimSpace(raw)) - if err != nil { - return "", err - } - if parsed.Scheme != "http" && parsed.Scheme != "https" { - return "", errors.New("must use http or https") - } - if parsed.Host == "" { - return "", errors.New("host is required") - } - if parsed.User != nil || parsed.RawQuery != "" || parsed.Fragment != "" || (parsed.Path != "" && parsed.Path != "/") { - return "", errors.New("must be an origin without credentials, path, query, or fragment") - } - return strings.TrimRight(parsed.String(), "/"), nil -} - func buildPostgresDSN() (string, error) { if dsn := os.Getenv("POSTGRES_DSN"); dsn != "" { return dsn, nil diff --git a/internal/server/detail_html_url.go b/internal/server/detail_html_url.go deleted file mode 100644 index dca459b..0000000 --- a/internal/server/detail_html_url.go +++ /dev/null @@ -1,78 +0,0 @@ -package server - -import ( - "io" - "strings" - - "golang.org/x/net/html" -) - -var detailHTMLStorageImagePrefixes = []string{ - "/ids-storage/material-images/", - "/ids-storage/catalog/", -} - -// completeDetailHTMLImageURLs completes only known storage-relative image -// paths. It deliberately leaves the query string untouched because it can -// contain a SigV4 signature whose encoding and parameter order are sensitive. -// Invalid HTML is returned unchanged so a read response never damages data. -func completeDetailHTMLImageURLs(raw, assetOrigin string) string { - assetOrigin = strings.TrimRight(strings.TrimSpace(assetOrigin), "/") - if raw == "" || assetOrigin == "" || !strings.Contains(strings.ToLower(raw), "