Browse Source

Replace c.Protocol(), c.Hostname() with c.BaseURL(). Add X-Forwarded-Prefix to Path

pull/103/head
Jose Franco 2 years ago
parent
commit
baf7d76f94
  1. 4
      docker-compose.yml
  2. 18
      docker/golang.Dockerfile
  3. 4
      src/cmd/root.go
  4. 4
      src/internal/rest/app.go

4
docker-compose.yml

@ -6,8 +6,8 @@ services:
options: options:
max-size: "200k" max-size: "200k"
max-file: "10" max-file: "10"
image: jffrancob/wa-multidevice:0.0.3
command: --os=Linux --debug true --basic-auth=admin:password
image: jffrancob/wa-multidevice:0.0.4
command: --os=Linux --debug true
environment: environment:
- SERVER_URL=http://${API_HOST-localhost}:${API_PORT-3000} - SERVER_URL=http://${API_HOST-localhost}:${API_PORT-3000}
working_dir: /whatsapp working_dir: /whatsapp

18
docker/golang.Dockerfile

@ -1,14 +1,13 @@
############################ ############################
# STEP 1 build executable binary # STEP 1 build executable binary
############################ ############################
FROM golang:1.20.5-alpine3.17 AS builder
FROM golang:1.21.3-alpine3.18 AS builder
RUN apk update && apk add --no-cache vips-dev gcc musl-dev gcompat ffmpeg RUN apk update && apk add --no-cache vips-dev gcc musl-dev gcompat ffmpeg
WORKDIR /whatsapp WORKDIR /whatsapp
COPY ./src . COPY ./src .
# Fetch dependencies. # Fetch dependencies.
RUN go mod download RUN go mod download
#RUN go mod tidy -e
# Install pkger # Install pkger
RUN go install github.com/markbates/pkger/cmd/pkger@latest RUN go install github.com/markbates/pkger/cmd/pkger@latest
# Build the binary. # Build the binary.
@ -16,22 +15,23 @@ RUN pkger
RUN go build -o /app/whatsapp RUN go build -o /app/whatsapp
#FROM builder AS dev
#RUN go install github.com/cosmtrek/air@latest
#RUN go mod tidy
#RUN go mod download
FROM builder AS dev
RUN go install github.com/cosmtrek/air@latest
RUN go mod tidy
RUN go mod download
RUN go mod tidy -e
#CMD ["air", "-c", ".air.toml"]
CMD ["air", "-c", ".air.toml"]
############################# #############################
## STEP 2 build a smaller image ## STEP 2 build a smaller image
############################# #############################
FROM alpine:3.17 as runtime
FROM alpine:3.18 as runtime
RUN apk update && apk add --no-cache vips ffmpeg RUN apk update && apk add --no-cache vips ffmpeg
COPY ./docs /docs COPY ./docs /docs
WORKDIR /app WORKDIR /app
# Copy compiled from builder. # Copy compiled from builder.
COPY --from=builder /app/whatsapp /app/whatsapp COPY --from=builder /app/whatsapp /app/whatsapp
# Run the binary. # Run the binary.
ENTRYPOINT ["/app/whatsapp"]
ENTRYPOINT ["/app/whatsapp"]

4
src/cmd/root.go

@ -128,13 +128,13 @@ func runRest(_ *cobra.Command, _ []string) {
{"url": string(serverURL)}, {"url": string(serverURL)},
} }
return c.Render("doc", fiber.Map{ return c.Render("doc", fiber.Map{
"AppHost": fmt.Sprintf("%s://%s", c.Protocol(), c.Hostname()),
"AppHost": fmt.Sprintf("%s", c.BaseURL()),
"Spec": toJSON(spec), "Spec": toJSON(spec),
"BasicAuthToken": c.UserContext().Value("token"), "BasicAuthToken": c.UserContext().Value("token"),
}) })
} else { } else {
return c.Render("index", fiber.Map{ return c.Render("index", fiber.Map{
"AppHost": fmt.Sprintf("%s://%s", c.Protocol(), c.Hostname()),
"AppHost": fmt.Sprintf("%s", c.BaseURL()),
"AppVersion": config.AppVersion, "AppVersion": config.AppVersion,
"BasicAuthToken": c.UserContext().Value("token"), "BasicAuthToken": c.UserContext().Value("token"),
"MaxFileSize": humanize.Bytes(uint64(config.WhatsappSettingMaxFileSize)), "MaxFileSize": humanize.Bytes(uint64(config.WhatsappSettingMaxFileSize)),

4
src/internal/rest/app.go

@ -30,8 +30,8 @@ func (handler *App) Login(c *fiber.Ctx) error {
Code: "SUCCESS", Code: "SUCCESS",
Message: "Login success", Message: "Login success",
Results: map[string]any{ Results: map[string]any{
"qr_link": fmt.Sprintf("%s://%s/%s", c.Protocol(), c.Hostname(), response.ImagePath),
"qr_duration": response.Duration,
"qr_link": fmt.Sprintf("%s%s/%s", c.BaseURL(), c.Get("X-Forwarded-Prefix"), response.ImagePath),
"qr_duration": response.Duration,
}, },
}) })
} }

Loading…
Cancel
Save