So. I have a stucture like this:
app
-api
-templates
-examples
-html
using echo like this
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
Root: "examples/html",
Browse: true,
IgnoreBase: true,
}))
and it works perfect when I run it locally
but when i put this in docker-container
then i get error trying to get fonts and other params for page
2023-05-03T19:14:48Z ERR error="code=400, message=failed to parse page id: invalid UUID length: 16" environment=dev latency=0 method=GET path=/i/blocks/index.css query= version=v0.0.0
/i/ – is the group path in api
locally it gets handled by IgnoreBase: true in middleware.StaticConfig above
not so in docker
here’s part of the docker file after build:
RUN go build myApp
FROM debian:buster
WORKDIR /app
COPY templates/ templates/
COPY examples/html/ examples/html/
COPY --from=build_stage /app/app-server /app/app-server
EXPOSE 8080
ENTRYPOINT [ "/app/app-server"]
everything else works perfect, it sees templates, gets info from them, but fails to get statics from examples/html
P>S> would be perfect if solution uses go:embed, but just making it run properly would be great enough )))
P>P>S>
There is a template that contains <link rel="stylesheet" href="./blocks/index.css">
to get the page I call Get http://localhost:8080/i/:id
through middleware it should call examples/html/blocks/index.css
but instead it calls to /i/blocks/index.css
as mentioned above it works perfect when i run the app locally, but when it is in a container it fails with mistake above, because middleware doesn’t remove junk from the path like it does when run locally.
UPD: it stopped working locally too. Now I don’t understand anything.
2
Answers
Closing this issue. My guess there was a problem in cache or smth. Because through middleware it doesn't work locally either.
It works like this
both locally and through container will post separate question on how to make it look good
Based on the information you provided, it seems like the issue might be related to the path resolution in the Docker container. Let’s try to fix it by using the absolute path for the Root configuration in the middleware.StaticConfig:
With these changes, your application should be able to serve the static files correctly when running inside a Docker container.
This solution uses the embed package and the http.FS for serving static files. It also makes sure that the absolute path is used for the Root configuration in the middleware.StaticConfig.