Pass things around via query params
parent
fb02cc994a
commit
da6eaca26f
|
|
@ -11,10 +11,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Root string
|
Root string
|
||||||
Port string
|
Port string
|
||||||
Head string
|
Head string
|
||||||
Foot string
|
Foot string
|
||||||
|
OAuthServer string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -30,6 +31,7 @@ func Refresh() {
|
||||||
as.Append(args.STRING, "root", "root dir path", "./public")
|
as.Append(args.STRING, "root", "root dir path", "./public")
|
||||||
as.Append(args.STRING, "port", "port to listen on", "39909")
|
as.Append(args.STRING, "port", "port to listen on", "39909")
|
||||||
as.Append(args.STRING, "wrap", "file with http header/footer", "./wrapper.html")
|
as.Append(args.STRING, "wrap", "file with http header/footer", "./wrapper.html")
|
||||||
|
as.Append(args.STRING, "oauth", "oauth URL", "")
|
||||||
if err := as.Parse(); err != nil {
|
if err := as.Parse(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
@ -49,4 +51,5 @@ func Refresh() {
|
||||||
Port = ":" + strings.TrimPrefix(as.Get("port").GetString(), ":")
|
Port = ":" + strings.TrimPrefix(as.Get("port").GetString(), ":")
|
||||||
Head = string(bs[0])
|
Head = string(bs[0])
|
||||||
Foot = string(bs[1])
|
Foot = string(bs[1])
|
||||||
|
OAuthServer = as.Get("oauth").GetString()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,10 @@ package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"local/notes-server/config"
|
||||||
|
"local/oauth2/oauth2client"
|
||||||
"local/router"
|
"local/router"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -14,19 +17,19 @@ func (s *Server) Routes() error {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
path: fmt.Sprintf("notes/%s%s", wildcard, wildcard),
|
path: fmt.Sprintf("notes/%s%s", wildcard, wildcard),
|
||||||
handler: s.notes,
|
handler: s.authenticate(s.notes),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: fmt.Sprintf("edit/%s%s", wildcard, wildcard),
|
path: fmt.Sprintf("edit/%s%s", wildcard, wildcard),
|
||||||
handler: s.edit,
|
handler: s.authenticate(s.edit),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: fmt.Sprintf("submit/%s%s", wildcard, wildcard),
|
path: fmt.Sprintf("submit/%s%s", wildcard, wildcard),
|
||||||
handler: s.submit,
|
handler: s.authenticate(s.submit),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: fmt.Sprintf("create/%s%s", wildcard, wildcard),
|
path: fmt.Sprintf("create/%s%s", wildcard, wildcard),
|
||||||
handler: s.create,
|
handler: s.authenticate(s.create),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,3 +40,16 @@ func (s *Server) Routes() error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) authenticate(foo http.HandlerFunc) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if config.OAuthServer != "" {
|
||||||
|
err := oauth2client.Authenticate(config.OAuthServer, w, r)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foo(w, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue