|
@@ -2,50 +2,27 @@ package main
|
2
|
2
|
|
3
|
3
|
import (
|
4
|
4
|
"fmt"
|
5
|
|
- "html/template"
|
6
|
|
- "log"
|
7
|
5
|
"net/http"
|
8
|
6
|
"os"
|
9
|
7
|
|
10
|
8
|
"github.com/gorilla/mux"
|
|
9
|
+ "github.com/isomorphicgo/isogoapp/handlers"
|
11
|
10
|
)
|
12
|
11
|
|
13
|
|
-var webappRoot string = os.Getenv("ISOGO_APP_ROOT")
|
14
|
|
-
|
15
|
|
-func indexHandler(w http.ResponseWriter, r *http.Request) {
|
16
|
|
- renderTemplate(w, webappRoot+"/templates/index.html", nil)
|
17
|
|
-}
|
18
|
|
-
|
19
|
|
-// Template rendering function
|
20
|
|
-func renderTemplate(w http.ResponseWriter, templateFile string, templateData interface{}) {
|
21
|
|
-
|
22
|
|
- t, err := template.ParseFiles(templateFile)
|
23
|
|
- if err != nil {
|
24
|
|
- log.Fatal("Error encountered while parsing the template: ", err)
|
25
|
|
- }
|
26
|
|
- t.Execute(w, templateData)
|
27
|
|
-}
|
28
|
|
-
|
29
|
|
-func gopherjsScriptHandler(w http.ResponseWriter, r *http.Request) {
|
30
|
|
- http.ServeFile(w, r, webappRoot+"/client/client.js")
|
31
|
|
-}
|
32
|
|
-
|
33
|
|
-func gopherjsScriptMapHandler(w http.ResponseWriter, r *http.Request) {
|
34
|
|
- http.ServeFile(w, r, webappRoot+"/client/client.js.map")
|
35
|
|
-}
|
|
12
|
+var WebAppRoot string = os.Getenv("ISOGO_APP_ROOT")
|
36
|
13
|
|
37
|
14
|
func main() {
|
38
|
15
|
|
39
|
|
- if webappRoot == "" {
|
|
16
|
+ if WebAppRoot == "" {
|
40
|
17
|
fmt.Println("The ISOGO_APP_ROOT environment variable must be set before the web server instance can be started.")
|
41
|
18
|
os.Exit(1)
|
42
|
19
|
}
|
43
|
20
|
|
44
|
|
- fs := http.FileServer(http.Dir(webappRoot + "/static"))
|
|
21
|
+ fs := http.FileServer(http.Dir(WebAppRoot + "/static"))
|
45
|
22
|
r := mux.NewRouter()
|
46
|
|
- r.HandleFunc("/", indexHandler)
|
47
|
|
- r.HandleFunc("/js/client.js", gopherjsScriptHandler)
|
48
|
|
- r.HandleFunc("/js/client.js.map", gopherjsScriptMapHandler)
|
|
23
|
+ r.HandleFunc("/", handlers.IndexHandler)
|
|
24
|
+ r.HandleFunc("/js/client.js", handlers.GopherjsScriptHandler)
|
|
25
|
+ r.HandleFunc("/js/client.js.map", handlers.GopherjsScriptMapHandler)
|
49
|
26
|
http.Handle("/", r)
|
50
|
27
|
http.Handle("/static/", http.StripPrefix("/static", fs))
|
51
|
28
|
http.ListenAndServe(":8080", nil)
|