Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6d43699ef | ||
|
|
618b9ed513 | ||
|
|
0595c49fc2 | ||
|
|
da6eaca26f | ||
|
|
fb02cc994a | ||
|
|
a80f9613ef |
1
.gitignore
vendored
Normal file → Executable file
1
.gitignore
vendored
Normal file → Executable file
@@ -4,3 +4,4 @@ gollum
|
||||
*.sw*
|
||||
**/*.sw*
|
||||
notes-server
|
||||
exec-notes-server
|
||||
|
||||
16
Dockerfile
Executable file
16
Dockerfile
Executable file
@@ -0,0 +1,16 @@
|
||||
|
||||
FROM golang:1.13-alpine as certs
|
||||
RUN apk update && apk add --no-cache ca-certificates
|
||||
|
||||
FROM busybox:glibc
|
||||
RUN mkdir -p /var/log
|
||||
WORKDIR /main
|
||||
COPY --from=certs /etc/ssl/certs /etc/ssl/certs
|
||||
|
||||
COPY . .
|
||||
|
||||
ENV GOPATH=""
|
||||
ENV MNT="/mnt/"
|
||||
ENTRYPOINT ["/main/exec-notes-server"]
|
||||
CMD []
|
||||
|
||||
3
TODO
3
TODO
@@ -5,3 +5,6 @@ x create dir
|
||||
TOC levels
|
||||
delete pages
|
||||
search
|
||||
move auth as flag in router
|
||||
. and ../** as roots cause bugs in listing and loading and linking
|
||||
`create` at root is a 400, base= in URL (when `create` input is empty)
|
||||
|
||||
@@ -15,6 +15,7 @@ var (
|
||||
Port string
|
||||
Head string
|
||||
Foot string
|
||||
OAuthServer string
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -30,6 +31,7 @@ func Refresh() {
|
||||
as.Append(args.STRING, "root", "root dir path", "./public")
|
||||
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, "oauth", "oauth URL", "")
|
||||
if err := as.Parse(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -49,4 +51,5 @@ func Refresh() {
|
||||
Port = ":" + strings.TrimPrefix(as.Get("port").GetString(), ":")
|
||||
Head = string(bs[0])
|
||||
Foot = string(bs[1])
|
||||
OAuthServer = as.Get("oauth").GetString()
|
||||
}
|
||||
|
||||
@@ -18,8 +18,10 @@ type Path struct {
|
||||
func NewPathFromLocal(p string) Path {
|
||||
splits := strings.SplitN(p, path.Base(config.Root), 2)
|
||||
href := splits[0]
|
||||
if len(splits) > 1 {
|
||||
if len(splits) > 1 && splits[0] == "" {
|
||||
href = splits[1]
|
||||
} else {
|
||||
href = strings.Join(splits, path.Base(config.Root))
|
||||
}
|
||||
href = path.Join("/notes", href)
|
||||
return NewPathFromURL(href)
|
||||
|
||||
@@ -2,7 +2,10 @@ package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"local/notes-server/config"
|
||||
"local/oauth2/oauth2client"
|
||||
"local/router"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -14,19 +17,19 @@ func (s *Server) Routes() error {
|
||||
}{
|
||||
{
|
||||
path: fmt.Sprintf("notes/%s%s", wildcard, wildcard),
|
||||
handler: s.notes,
|
||||
handler: s.authenticate(s.notes),
|
||||
},
|
||||
{
|
||||
path: fmt.Sprintf("edit/%s%s", wildcard, wildcard),
|
||||
handler: s.edit,
|
||||
handler: s.authenticate(s.edit),
|
||||
},
|
||||
{
|
||||
path: fmt.Sprintf("submit/%s%s", wildcard, wildcard),
|
||||
handler: s.submit,
|
||||
handler: s.authenticate(s.submit),
|
||||
},
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
padding: .5pt;
|
||||
border-radius: 6px;
|
||||
}
|
||||
img {
|
||||
max-height: 400px;
|
||||
}
|
||||
</style>
|
||||
</header>
|
||||
<body height="100%">
|
||||
|
||||
Reference in New Issue
Block a user