2024-12-06 21:57:47 +00:00
|
|
|
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
|
|
|
|
}
|
2024-12-06 22:53:02 +00:00
|
|
|
http.ServeFile(w, r, "/app/data/it-jobbank.json")
|
2024-12-06 21:57:47 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|