-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.go
53 lines (41 loc) · 1.04 KB
/
index.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
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"net/http"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
func main() {
// Init a new router
r := mux.NewRouter()
// Define a subrouter for all /api routes
api := r.PathPrefix("/api").Subrouter()
// Define api routes
api.
Methods("GET").
Path("/todos").
HandlerFunc(TodoIndex)
api.
Methods("POST").
Path("/todos").
HandlerFunc(TodoCreate)
api.
Methods("GET").
Path("/todos/{todoId}").
HandlerFunc(TodoShow)
api.
Methods("DELETE").
Path("/todos/{todoId}").
HandlerFunc(TodoDelete)
api.
Methods("PUT").
Path("/todos/{todoId}").
HandlerFunc(TodoUpdate)
// Serve all css, js from /assets path
r.PathPrefix("/assets/").Handler(http.StripPrefix("/assets/", http.FileServer(http.Dir("./client/dist"))))
// Point all the other requests to the client
r.PathPrefix("/").HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
http.ServeFile(w, req, "./client/dist/index.html")
})
// Start out server at :8080
http.ListenAndServe(":8080", handlers.RecoveryHandler()(r))
}