add docker and use route grouping for API routes

This commit is contained in:
Arya 2023-08-27 20:21:47 +05:30
parent f7dc568f72
commit 47b56466ba
Signed by: arya
GPG Key ID: 842D12BDA50DF120
4 changed files with 40 additions and 6 deletions

20
Dockerfile Normal file
View File

@ -0,0 +1,20 @@
FROM --platform=$BUILDPLATFORM golang:alpine AS build
ARG TARGETARCH
WORKDIR /src
RUN apk --no-cache add git ca-certificates
COPY . .
RUN go mod download
RUN GOOS=linux GOARCH=$TARGETARCH go build -o /src/mozhi
FROM alpine:3.16 as bin
WORKDIR /app
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs
COPY --from=build /src/mozhi .
EXPOSE 3000
CMD ["/app/mozhi", "serve"]

View File

@ -1,6 +1,9 @@
# TODO
- Create a web interface
- Make CLI usable
- API Docs
- Support for disabling engines
- Support for changing LibreTranslate instance
- Add actual explanations for CLI arguments
- Proper Error handling for requests.go
- Tell which language Detect Language chose -- Only support for deepl and google is pending

12
compose.yml Normal file
View File

@ -0,0 +1,12 @@
version: "3"
services:
mozhi:
build: .
restart: unless-stopped
ports:
- "3000:3000"
healthcheck:
test: wget -nv --tries=1 --spider http://127.0.0.1:3000/api/v1/version || exit 1
interval: 30s
timeout: 5s
retries: 2

View File

@ -79,10 +79,6 @@ func Serve(port string) {
})
app.Get("/", pages.HandleIndex)
app.Get("/api/translate", pages.HandleTranslate)
app.Get("/api/source_languages", pages.HandleSourceLanguages)
app.Get("/api/target_languages", pages.HandleTargetLanguages)
app.Get("/api/tts", pages.HandleTTS)
app.Static("/css", "./public/css", staticConfig)
app.Static("/robots.txt", "./public/robots.txt", staticConfig)
app.Static("/favicon.ico", "./public/assets/favicon.ico", staticConfig)
@ -90,8 +86,11 @@ func Serve(port string) {
// app.Get("/about", pages.HandleAbout)
api := app.Group("/api")
v1 := api.Group("/v1")
v1.Get("/version", func(c *fiber.Ctx) error {
api.Get("/translate", pages.HandleTranslate)
api.Get("/source_languages", pages.HandleSourceLanguages)
api.Get("/target_languages", pages.HandleTargetLanguages)
api.Get("/tts", pages.HandleTTS)
api.Get("/version", func(c *fiber.Ctx) error {
return c.JSON(fiber.Map{
"version": utils.Version(),
"fiberversion": fiber.Version,