Add index and fe handlers.
[armadillo.git] / src / server.go
1 package server
2
3 import (
4 "fmt"
5 "http"
6 "io"
7 "os"
8 "path"
9 )
10
11 const kFrontEndFiles = "/Users/rsesek/Projects/armadillo/out/fe"
12
13 func testHandler(connection *http.Conn, request *http.Request) {
14 fmt.Print("Got a request");
15 io.WriteString(connection, "Hello world")
16 }
17
18 func indexHandler(connection *http.Conn, request *http.Request) {
19 fd, err := os.Open(path.Join(kFrontEndFiles, "index.html"), os.O_RDONLY, 0)
20 if err != nil {
21 fmt.Print("Error opening file ", err.String(), "\n")
22 return
23 }
24 io.Copy(connection, fd)
25 }
26
27 func RunFrontEnd() {
28 mux := http.NewServeMux()
29 mux.HandleFunc("/", indexHandler)
30 mux.Handle("/fe/", http.FileServer(kFrontEndFiles, "/fe/"))
31 mux.HandleFunc("/test", testHandler)
32
33 error := http.ListenAndServe(":8084", mux)
34 fmt.Printf("error %v", error)
35 }