commit f193b395f34fadbf2ff15a8839ca58bd45ab7d84 Author: hook-lord Date: Fri Dec 6 22:57:47 2024 +0100 initial commit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c0c26c1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:1.23 AS builder +WORKDIR /app +COPY go.mod go.sum ./ +RUN go mod download +COPY *.go ./ +RUN CGO_ENABLED=0 GOOS=linux go build -o job-api + +FROM alpine:3.18 +WORKDIR /app +COPY --from=builder /app/job-api . +CMD ["./job-api"] diff --git a/gitea/workflows/build.yaml b/gitea/workflows/build.yaml new file mode 100644 index 0000000..5e19b83 --- /dev/null +++ b/gitea/workflows/build.yaml @@ -0,0 +1,31 @@ +name: Build and Push Docker Image + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v4 + + - name: Log in to Gitea Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ secrets.REGISTRY }} + username: ${{ secrets.USER }} + password: ${{ secrets.TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ secrets.REGISTRY }}/rannes.dev/sw-jobs-api:latest diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6ac0f17 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module gitea.rannes.dev/rannes.dev/sw-jobs-api + +go 1.23.3 diff --git a/main.go b/main.go new file mode 100644 index 0000000..efc8ea9 --- /dev/null +++ b/main.go @@ -0,0 +1,52 @@ +package main + +import ( + "log" + "net/http" +) + +const PORT = "8080" + +func main() { + + mux := http.NewServeMux() + + mux.HandleFunc("/thehub", func(w http.ResponseWriter, r *http.Request) { + if !setHeader(w, r){ + return + } + http.ServeFile(w, r, "/app/data/thehub.json") + }) + + mux.HandleFunc("/itjobbank", func(w http.ResponseWriter, r *http.Request) { + if !setHeader(w, r) { + return + } + http.ServeFile(w, r, "/app/data/itjobbank.json") + }) + + mux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + return + }) + + server := &http.Server{ + Addr: ":" + PORT, + Handler: mux, + } + log.Printf("Server starting on port %s", PORT) + log.Fatal(server.ListenAndServe()) +} + +func setHeader(w http.ResponseWriter, r *http.Request) bool { + w.Header().Set("Access-Control-Allow-Origin", "*") + w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS") + w.Header().Set("Content-Type", "application/json") + + if r.Method == "OPTIONS" { + w.WriteHeader(http.StatusOK) + return false + } + + return true +} diff --git a/thehub.json b/thehub.json new file mode 100644 index 0000000..36d1e24 --- /dev/null +++ b/thehub.json @@ -0,0 +1,3 @@ +{ + "message": "skibidi working!" +}