2023-03-15 00:05:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-04-25 09:37:42 +00:00
|
|
|
"context"
|
|
|
|
"errors"
|
2023-03-15 00:05:24 +00:00
|
|
|
"log"
|
2023-04-25 09:37:42 +00:00
|
|
|
"os"
|
2023-05-02 00:12:43 +00:00
|
|
|
|
2023-05-03 21:50:08 +00:00
|
|
|
"personalwebsite/apps"
|
2023-05-16 10:51:28 +00:00
|
|
|
"personalwebsite/routes"
|
2023-04-29 13:58:39 +00:00
|
|
|
"personalwebsite/wde"
|
2023-04-25 09:37:42 +00:00
|
|
|
"personalwebsite/webfilesystem"
|
2023-03-15 00:05:24 +00:00
|
|
|
|
2023-04-25 09:37:42 +00:00
|
|
|
"github.com/joho/godotenv"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
2023-03-15 00:05:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2023-04-25 09:37:42 +00:00
|
|
|
if err := godotenv.Load(); err != nil {
|
|
|
|
println("No .env file found")
|
|
|
|
}
|
|
|
|
|
|
|
|
mongoConnect, err := FindEnv("MONGO_CONNECT")
|
|
|
|
if err != nil {
|
|
|
|
panic(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
dBName, err := FindEnv("DATABASE")
|
|
|
|
if err != nil {
|
|
|
|
panic(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
webFsCollection, err := FindEnv("COLLECTION_WEBFS")
|
|
|
|
if err != nil {
|
|
|
|
panic(err.Error())
|
|
|
|
}
|
|
|
|
|
2023-09-13 01:37:49 +00:00
|
|
|
// publicPort, err := FindEnv("PUBLIC_PORT")
|
|
|
|
// if err != nil {
|
|
|
|
// panic(err.Error())
|
|
|
|
// }
|
2023-05-23 23:19:21 +00:00
|
|
|
|
|
|
|
privatePort, err := FindEnv("PRIVATE_PORT")
|
|
|
|
if err != nil {
|
|
|
|
panic(err.Error())
|
|
|
|
}
|
|
|
|
|
2023-04-25 09:37:42 +00:00
|
|
|
clientOptions := options.Client().ApplyURI(mongoConnect)
|
|
|
|
client, err := mongo.Connect(context.TODO(), clientOptions)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
err = client.Ping(context.TODO(), nil)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-05-16 10:51:28 +00:00
|
|
|
webfs := webfilesystem.NewWebFileSystem(client, dBName, webFsCollection)
|
|
|
|
appsStorage := apps.NewApplicationsStorage(map[string]apps.WebDEApplication{}, webfs)
|
2023-03-18 00:34:56 +00:00
|
|
|
|
2023-05-01 12:32:41 +00:00
|
|
|
webde := wde.NewWDE(webfs)
|
2023-04-29 20:17:34 +00:00
|
|
|
|
2023-05-18 01:57:44 +00:00
|
|
|
//TODO Split to different apps init for private and public?
|
2023-09-13 01:37:49 +00:00
|
|
|
// persPropsApp := aboutme.NewAboutMeApp(webfs)
|
|
|
|
// finderApp := finder.NewFinderApplication(webfs)
|
|
|
|
// imgViewerApp := imgviewer.NewImgViewerApp(webfs)
|
|
|
|
// blogViewerApp := blogviewer.NewBlogViewerApp(webfs)
|
|
|
|
// blogWriterApp := blogwriter.NewBlogWriterApp(webfs)
|
|
|
|
// sunBoardApp := sunboard.NewSunboardApp(webfs, webde, appsStorage)
|
|
|
|
|
|
|
|
// appsStorage.Apps["personal-properties"] = persPropsApp
|
|
|
|
// appsStorage.Apps["finder"] = finderApp
|
|
|
|
// appsStorage.Apps["img-viewer"] = imgViewerApp
|
|
|
|
// appsStorage.Apps[blogViewerApp.GetAppID()] = blogViewerApp
|
|
|
|
// appsStorage.Apps["BlogWriter"] = blogWriterApp
|
|
|
|
// appsStorage.Apps["Sunboard"] = sunBoardApp
|
|
|
|
|
|
|
|
// go routes.PublicRoutes(publicPort, webfs, webde, appsStorage)
|
2023-05-23 23:19:21 +00:00
|
|
|
routes.PrivateRoutes(privatePort, webfs, webde, appsStorage)
|
2023-03-15 00:05:24 +00:00
|
|
|
}
|
|
|
|
|
2023-07-22 15:56:51 +00:00
|
|
|
// TODO to for loop with aal vars in slice
|
2023-04-25 09:37:42 +00:00
|
|
|
func FindEnv(parameter string) (string, error) {
|
|
|
|
path, exists := os.LookupEnv(parameter)
|
|
|
|
|
|
|
|
if exists {
|
|
|
|
println("[ENV] Requsted " + parameter + " = " + path) //FIXME Only in Debug log
|
|
|
|
return path, nil
|
|
|
|
} else {
|
|
|
|
panic("[ENV] Requsted " + parameter + " not found")
|
|
|
|
return "", errors.New("env parameter not found")
|
|
|
|
}
|
|
|
|
}
|