Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ FROM scratch

COPY --from=build /app/anonymousoverflow /anonymousoverflow
COPY --from=build /app/healthcheck /healthcheck
COPY templates /templates
COPY public /public
COPY --from=build /etc/ssl/certs /etc/ssl/certs

HEALTHCHECK --interval=60s --timeout=5s --start-period=2s --retries=3 CMD [ "/healthcheck","http://localhost:8080/healthz" ]

EXPOSE 8080

CMD ["/anonymousoverflow"]
CMD ["/anonymousoverflow"]
18 changes: 15 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import (
"anonymousoverflow/env"
"anonymousoverflow/src/middleware"
"anonymousoverflow/src/routes"
"embed"
"fmt"
"html/template"
"io/fs"
"net/http"
"os"

"github.com/gin-gonic/gin"
Expand All @@ -13,6 +17,12 @@ import (
"github.com/tavsec/gin-healthcheck/config"
)

//go:embed templates/*
var templates embed.FS

//go:embed public/*
var public embed.FS

func main() {

env.RunChecks()
Expand All @@ -29,19 +39,21 @@ func main() {

if os.Getenv("DEV") != "true" {
gin.SetMode(gin.ReleaseMode)
fmt.Printf("Running in production mode. Listening on %s:%s.", host, port)
fmt.Printf("Running in production mode. Listening on %s:%s.\n", host, port)
}

r := gin.Default()

r.LoadHTMLGlob("templates/*")
templ := template.Must(template.New("").ParseFS(templates, "templates/*"))
r.SetHTMLTemplate(templ)

r.Use(gin.Recovery())
r.Use(middleware.XssPreventionHeaders())
r.Use(middleware.OptionsMiddleware())
r.Use(middleware.Ratelimit())

r.GET("/static/*filepath", routes.StaticContent)
static, _ := fs.Sub(public, "public")
r.StaticFS("/static", http.FS(static))

r.GET("/robots.txt", func(c *gin.Context) {
c.String(200, "User-agent: *\nDisallow: /")
Expand Down
14 changes: 0 additions & 14 deletions src/routes/static.go

This file was deleted.