-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
62 lines (46 loc) · 1.63 KB
/
server.go
File metadata and controls
62 lines (46 loc) · 1.63 KB
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
54
55
56
57
58
59
60
61
62
// Copyright 2016 The front Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package main
import (
"net/http"
"os"
"github.com/codegangsta/negroni"
"github.com/goincremental/negroni-sessions"
"github.com/goincremental/negroni-sessions/cookiestore"
"github.com/julienschmidt/httprouter"
"github.com/repejota/logger"
"github.com/tvtio/front/routes"
)
// Start starts the HTTP Server of the application
// * Define the routes
// * Setup middleware engine
//
func Start() error {
l := logger.New("default")
// Setup middleware
middle := negroni.Classic()
store := cookiestore.New([]byte("keyboard cat"))
middle.Use(sessions.Sessions("tvtio", store))
// Setup router
router := httprouter.New()
router.GET("/", routes.Index)
router.GET("/search", routes.Search)
router.GET("/movie/:id", routes.Movie)
router.GET("/tv/:id", routes.TV)
router.GET("/tv/:id/season/:snumber", routes.Season)
router.GET("/tv/:id/season/:snumber/episode/:enumber", routes.Episode)
router.GET("/person/:id", routes.Person)
router.GET("/about", routes.About)
router.GET("/policy", routes.Policy)
router.GET("/terms", routes.Terms)
router.GET("/support", routes.Support)
router.ServeFiles("/css/*filepath", http.Dir(os.Getenv("TEMPLATEPATH")+"/css"))
router.ServeFiles("/js/*filepath", http.Dir(os.Getenv("TEMPLATEPATH")+"/js"))
router.ServeFiles("/img/*filepath", http.Dir(os.Getenv("TEMPLATEPATH")+"/img"))
// Apply middleware to the router
middle.UseHandler(router)
l.Infof("Listening at :8080")
// Start server
return http.ListenAndServe(":8080", middle)
}