Files
email-notification/main.go
teddys48 ce3dcd2aec
All checks were successful
Build and Deploy / cleaning (push) Successful in 10s
Build and Deploy / build_image (push) Successful in 3m3s
Build and Deploy / deploy (push) Successful in 9s
update
2026-02-11 17:34:57 +07:00

48 lines
1.0 KiB
Go

package main
import (
"context"
"email-notification/config"
"email-notification/route"
"log"
"net/http"
"os"
"github.com/joho/godotenv"
)
func corsMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*") // Ganti * dengan origin spesifik jika perlu
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, FETCH")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
}
next.ServeHTTP(w, r)
})
}
func main() {
log.Println("Email Notification Service")
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
db := config.NewDatabase().WithContext(context.Background())
mux := http.NewServeMux()
handlerWithCORS := corsMiddleware(mux)
route.Route(db, mux)
port := os.Getenv("PORT")
http.ListenAndServe(":"+port, handlerWithCORS)
}