Move app from server

This commit is contained in:
2015-03-07 16:44:50 +07:00
parent 525925691b
commit da9ec3482e
10 changed files with 39 additions and 79 deletions
-15
View File
@@ -1,15 +0,0 @@
package server
import (
"net/http"
)
func appHelloHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf8")
helloTmpl.ExecuteTemplate(w, "hello", map[string]interface{}{})
}
func appAppHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf8")
appTmpl.ExecuteTemplate(w, "app", map[string]interface{}{})
}
-32
View File
@@ -1,32 +0,0 @@
var Menu = React.createClass({
getInitialState: function() {
return {teams: []};
},
componentDidMount: function() {
this.loadTeams();
},
loadTeams: function() {
$.get(this.props.api, function(res){
this.setState({teams: res})
}.bind(this));
},
render: function() {
var renderTeam = function(team) {
return (
<li className="nav team">{team.name}</li>
)
};
return (
<ul>
<li className="nav empact">Empact</li>
<li className="nav dash">Dashboard</li>
<li className="nav repos">Repos</li>
<li className="nav header">Teams:</li>
{this.state.teams.map(renderTeam)}
</ul>
);
}
});
-20
View File
@@ -1,20 +0,0 @@
{{define "app"}}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<title>Empact</title>
<link rel="stylesheet" href="/app/hello.css">
</head>
<body>
<h1>Please Sign in with your GitHub account</h1>
<a href="/auth/signin">
<img src="/app/github_mark_120.png">
</a>
<script src="/app/hello.js"></script>
</body>
</html>
{{end}}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

-29
View File
@@ -1,29 +0,0 @@
* {
box-sizing: border-box;
font-family: 'Helvetica Neue', Helvetica, sans-serif;
font-weight: 400;
}
html, body {
margin: 0;
padding: 0;
}
h1 {
position: absolute;
left: 15%;
top: 20%;
width: 70%;
text-align: center;
color: #aaa;
}
a {
position: absolute;
top: 40%;
width: 100%;
text-align: center;
}
img {
width: 60px;
}
View File
-20
View File
@@ -1,20 +0,0 @@
{{define "hello"}}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<title>Empact</title>
<link rel="stylesheet" href="/static/hello.css">
</head>
<body>
<h1>Please Sign in with your GitHub account</h1>
<a href="/auth/signin">
<img src="/static/github_mark_120.png">
</a>
<script src="/static/hello.js"></script>
</body>
</html>
{{end}}
+1 -23
View File
@@ -2,26 +2,11 @@ package server
import (
"encoding/json"
"html/template"
"log"
"net/http"
"github.com/GeertJohan/go.rice"
)
var (
helloTmpl = template.New("hello")
appTmpl = template.New("app")
box = rice.MustFindBox("app")
)
func init() {
parseTemplate("hello.tmpl", helloTmpl)
parseTemplate("app.tmpl", appTmpl)
// Serving static files
http.Handle("/app/", http.StripPrefix("/app/", http.FileServer(box.HTTPBox())))
http.HandleFunc("/", sessionHandler)
http.HandleFunc("/hello", appHelloHandler)
http.HandleFunc("/app", appAppHandler)
@@ -43,20 +28,13 @@ func Start() {
http.ListenAndServe(":8080", nil)
}
func parseTemplate(file string, tmpl *template.Template) {
if tmplText, err := box.String(file); err == nil {
tmpl, _ = tmpl.Parse(tmplText)
} else {
panic(err)
}
}
func respondWith(w http.ResponseWriter, resp interface{}) {
b, err := json.Marshal(resp)
if err != nil {
panic(err)
}
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "application/json; charset=utf8")
w.Write(b)
}