2024-02-13 18:45:08 +01:00
|
|
|
package main
|
|
|
|
|
|
2024-02-14 14:55:41 +01:00
|
|
|
import (
|
2024-05-19 23:56:53 +02:00
|
|
|
"github.com/rs/cors"
|
2024-02-14 14:55:41 +01:00
|
|
|
"net/http"
|
2024-05-16 18:42:31 +02:00
|
|
|
"portfolio/api"
|
2024-05-16 17:36:44 +02:00
|
|
|
"portfolio/database"
|
2024-05-16 18:42:31 +02:00
|
|
|
"portfolio/web"
|
2024-02-14 14:55:41 +01:00
|
|
|
)
|
2024-02-13 18:45:08 +01:00
|
|
|
|
|
|
|
|
func main() {
|
2025-01-04 13:01:12 +01:00
|
|
|
//// load .env in runtime environment
|
|
|
|
|
//err := godotenv.Load()
|
|
|
|
|
//if err != nil {
|
|
|
|
|
// log.Fatalf(".env not found: %v", err)
|
|
|
|
|
// return
|
|
|
|
|
//}
|
2024-05-15 15:49:39 +02:00
|
|
|
|
2024-02-14 00:08:14 +01:00
|
|
|
//connect to database and migrate
|
2024-02-14 14:55:41 +01:00
|
|
|
database.DB()
|
2024-02-14 00:08:14 +01:00
|
|
|
|
2024-05-16 18:42:31 +02:00
|
|
|
//init web routes
|
2024-05-16 18:55:03 +02:00
|
|
|
webMux := web.WebRoutes()
|
2024-05-16 18:42:31 +02:00
|
|
|
// Run web server
|
2024-05-19 23:56:53 +02:00
|
|
|
go http.ListenAndServe(":4000", cors.AllowAll().Handler(webMux))
|
|
|
|
|
|
|
|
|
|
c := cors.New(cors.Options{
|
2024-06-25 01:46:54 +02:00
|
|
|
AllowedOrigins: []string{"http://localhost:4000", "https://*.dariusklein.nl", "https://*.portfolio.dariusklein.nl", "https://dariusklein.nl"},
|
2024-05-19 23:56:53 +02:00
|
|
|
AllowedMethods: []string{
|
|
|
|
|
http.MethodHead,
|
|
|
|
|
http.MethodGet,
|
|
|
|
|
http.MethodPost,
|
|
|
|
|
http.MethodPut,
|
|
|
|
|
http.MethodPatch,
|
|
|
|
|
http.MethodDelete,
|
|
|
|
|
},
|
|
|
|
|
AllowedHeaders: []string{"*"},
|
|
|
|
|
AllowCredentials: true,
|
|
|
|
|
})
|
2024-05-16 18:42:31 +02:00
|
|
|
|
|
|
|
|
//init api routes
|
2024-05-16 18:55:03 +02:00
|
|
|
apiMux := api.ApiRoutes()
|
2024-05-16 18:42:31 +02:00
|
|
|
//run api server
|
2024-05-19 23:56:53 +02:00
|
|
|
http.ListenAndServe(":4001", c.Handler(apiMux))
|
2024-05-16 18:42:31 +02:00
|
|
|
|
2024-02-13 18:45:08 +01:00
|
|
|
}
|