Begin dockerfile and create 404.html if not exists

This commit is contained in:
Nikurasu 2023-01-27 16:23:22 +01:00
parent 404224a155
commit a54a54df3c
No known key found for this signature in database
3 changed files with 19 additions and 1 deletions

View File

@ -0,0 +1,11 @@
FROM golang:alpine3.17 AS build
WORKDIR /build
COPY ./src ./src
WORKDIR /build/src
RUN ls
RUN go get .
RUN go build -o /build/static-hoster
FROM alpine:3.17 AS final
COPY --from=build /build/static-hoster /bin/static-hoster
CMD static-hoster

View File

@ -28,7 +28,7 @@ func Load() (env *Environment) {
defaultApiKey := "test123"
env = new(Environment)
env.RootDir = envReader("STATIC_HOSTER_HOME", fmt.Sprintf("%s/static-hoster/", os.Getenv("HOME")))
env.StaticDir = envReader("STATIC_HOSTER_HOST_DIR", fmt.Sprintf("%s/hosted/", env.RootDir))
env.StaticDir = envReader("STATIC_HOSTER_HOST_DIR", fmt.Sprintf("%shosted/", env.RootDir))
env.Port = fmt.Sprintf(":%s", envReader("STATIC_HOSTER_PORT", "8080"))
env.ApiKey = envReader("STATIC_HOSTER_API_KEY", defaultApiKey)
env.BaseRoute = envReader("STATIC_HOSTER_BASE_ROUTE", "/home")

View File

@ -1,12 +1,19 @@
package main
import (
"errors"
"fmt"
"os"
"nikurasu.gay/static-hoster/envloader"
"nikurasu.gay/static-hoster/router"
)
func main() {
var env = envloader.Load()
if _, err := os.Stat(fmt.Sprintf("%s404.html", env.StaticDir)); errors.Is(err, os.ErrNotExist) {
os.Create(fmt.Sprintf("%s404.html", env.StaticDir))
}
r := router.Create(env)
r.Run(env.Port)
}