add docker and use route grouping for API routes
This commit is contained in:
parent
f7dc568f72
commit
47b56466ba
4 changed files with 40 additions and 6 deletions
20
Dockerfile
Normal file
20
Dockerfile
Normal 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"]
|
3
TODO.md
3
TODO.md
|
@ -1,6 +1,9 @@
|
||||||
# TODO
|
# TODO
|
||||||
- Create a web interface
|
- Create a web interface
|
||||||
- Make CLI usable
|
- Make CLI usable
|
||||||
|
- API Docs
|
||||||
|
- Support for disabling engines
|
||||||
|
- Support for changing LibreTranslate instance
|
||||||
- Add actual explanations for CLI arguments
|
- Add actual explanations for CLI arguments
|
||||||
- Proper Error handling for requests.go
|
- Proper Error handling for requests.go
|
||||||
- Tell which language Detect Language chose -- Only support for deepl and google is pending
|
- Tell which language Detect Language chose -- Only support for deepl and google is pending
|
||||||
|
|
12
compose.yml
Normal file
12
compose.yml
Normal 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
|
|
@ -79,10 +79,6 @@ func Serve(port string) {
|
||||||
})
|
})
|
||||||
|
|
||||||
app.Get("/", pages.HandleIndex)
|
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("/css", "./public/css", staticConfig)
|
||||||
app.Static("/robots.txt", "./public/robots.txt", staticConfig)
|
app.Static("/robots.txt", "./public/robots.txt", staticConfig)
|
||||||
app.Static("/favicon.ico", "./public/assets/favicon.ico", staticConfig)
|
app.Static("/favicon.ico", "./public/assets/favicon.ico", staticConfig)
|
||||||
|
@ -90,8 +86,11 @@ func Serve(port string) {
|
||||||
// app.Get("/about", pages.HandleAbout)
|
// app.Get("/about", pages.HandleAbout)
|
||||||
|
|
||||||
api := app.Group("/api")
|
api := app.Group("/api")
|
||||||
v1 := api.Group("/v1")
|
api.Get("/translate", pages.HandleTranslate)
|
||||||
v1.Get("/version", func(c *fiber.Ctx) error {
|
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{
|
return c.JSON(fiber.Map{
|
||||||
"version": utils.Version(),
|
"version": utils.Version(),
|
||||||
"fiberversion": fiber.Version,
|
"fiberversion": fiber.Version,
|
||||||
|
|
Loading…
Reference in a new issue