-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
42 lines (33 loc) · 986 Bytes
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
"mrn-portfolio/controllers"
"mrn-portfolio/database"
"mrn-portfolio/utils"
"net/http"
"os"
"github.com/julienschmidt/httprouter"
)
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
db := database.DB{}
dbconn := db.Open()
router := httprouter.New()
s := controllers.Server{
DB: dbconn,
Router: router,
}
s.Router.ServeFiles("/static/*filepath", http.Dir("frontend/dist/static"))
s.Router.GET("/manifest.json", s.WebManifestHandler)
s.Router.GET("/browserconfig.xml", s.BrowserConfigFileHandler)
s.Router.GET("/yandex-browser-manifest.json", s.YanderBrowserFileHandler)
s.Router.GET("/manifest.webapp", s.ManifestWebAppFileHandler)
s.Router.GET("/", s.CreateHandler("homepage", s.HomeHandler))
s.Router.GET("/blog", s.CreateHandler("blog", s.BlogHandler))
err := http.ListenAndServe(":"+port, s.Router)
fmt.Printf("> Server is running in http://localhost:%s/\n", port)
utils.HandleError(err)
}