Add -baseurl command line argument
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
419571daf6
commit
40d1fc3879
55
main.go
55
main.go
|
@ -24,11 +24,10 @@ func init() {
|
|||
|
||||
var (
|
||||
mp PagesRepository
|
||||
)
|
||||
|
||||
const (
|
||||
ClientID = "https://wiki.p83.nl/"
|
||||
RedirectURI = "https://wiki.p83.nl/auth/callback"
|
||||
port = flag.Int("port", 8080, "listen port")
|
||||
baseurl = flag.String("baseurl", "", "baseurl")
|
||||
redirectURI string = ""
|
||||
)
|
||||
|
||||
type Backref struct {
|
||||
|
@ -164,7 +163,7 @@ func (*authHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
authURL := sess.AuthorizationEndpoint
|
||||
|
||||
verified, response, err := indieauth.VerifyAuthCode(ClientID, code, RedirectURI, authURL)
|
||||
verified, response, err := indieauth.VerifyAuthCode(*baseurl, code, redirectURI, authURL)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
|
@ -220,11 +219,11 @@ func (*authHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
sess.AuthorizationEndpoint = authURL.String()
|
||||
sess.Me = urlString
|
||||
sess.LoggedIn = false
|
||||
sess.RedirectURI = RedirectURI
|
||||
sess.RedirectURI = redirectURI
|
||||
sess.NextURI = "/"
|
||||
sess.State = state
|
||||
|
||||
newURL := indieauth.CreateAuthenticationURL(*authURL, urlString, ClientID, RedirectURI, state)
|
||||
newURL := indieauth.CreateAuthenticationURL(*authURL, urlString, *baseurl, redirectURI, state)
|
||||
|
||||
http.Redirect(w, r, newURL, 302)
|
||||
return
|
||||
|
@ -298,8 +297,7 @@ func (h *historyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func getPageBase() pageBaseInfo {
|
||||
clientID := ClientID
|
||||
redirectURI := RedirectURI
|
||||
clientID := *baseurl
|
||||
|
||||
pageBase := pageBaseInfo{
|
||||
BaseURL: clientID,
|
||||
|
@ -409,12 +407,12 @@ func (h *editHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
pageBase := getPageBase()
|
||||
data := editPage{
|
||||
pageBaseInfo: pageBase,
|
||||
Session: sess,
|
||||
Title: cleanTitle(page),
|
||||
Content: pageText,
|
||||
Editor: editor,
|
||||
Name: page,
|
||||
Backrefs: mpPage.Refs,
|
||||
Session: sess,
|
||||
Title: cleanTitle(page),
|
||||
Content: pageText,
|
||||
Editor: editor,
|
||||
Name: page,
|
||||
Backrefs: mpPage.Refs,
|
||||
}
|
||||
|
||||
t, err := template.ParseFiles("templates/layout.html", "templates/edit.html")
|
||||
|
@ -512,11 +510,11 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
pageBase := getPageBase()
|
||||
data := indexPage{
|
||||
pageBaseInfo: pageBase,
|
||||
Session: sess,
|
||||
Title: cleanTitle(page),
|
||||
Content: template.HTML(pageText),
|
||||
Name: page,
|
||||
Backrefs: mpPage.Refs,
|
||||
Session: sess,
|
||||
Title: cleanTitle(page),
|
||||
Content: template.HTML(pageText),
|
||||
Name: page,
|
||||
Backrefs: mpPage.Refs,
|
||||
}
|
||||
|
||||
t, err := template.ParseFiles("templates/layout.html", "templates/view.html")
|
||||
|
@ -584,10 +582,10 @@ func (h *recentHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
pageBase := getPageBase()
|
||||
err = t.Execute(w, recentPage{
|
||||
pageBaseInfo: pageBase,
|
||||
Session: sess,
|
||||
Title: "Recent changes",
|
||||
Name: "Recent changes",
|
||||
Recent: changes,
|
||||
Session: sess,
|
||||
Title: "Recent changes",
|
||||
Name: "Recent changes",
|
||||
Recent: changes,
|
||||
})
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
|
@ -612,10 +610,11 @@ type LinkResponse struct {
|
|||
}
|
||||
|
||||
func main() {
|
||||
var port int
|
||||
flag.IntVar(&port, "port", 8080, "http port")
|
||||
flag.Parse()
|
||||
|
||||
*baseurl = strings.TrimRight(*baseurl, "/") + "/"
|
||||
redirectURI = fmt.Sprintf("%sauth/callback", *baseurl)
|
||||
|
||||
mp = NewFilePages("data")
|
||||
|
||||
http.Handle("/auth/", &authHandler{})
|
||||
|
@ -684,6 +683,6 @@ func main() {
|
|||
http.Handle("/recent/", &recentHandler{})
|
||||
http.Handle("/", &indexHandler{})
|
||||
|
||||
fmt.Printf("Running on port %d\n", port)
|
||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
|
||||
fmt.Printf("Running on port %d\n", *port)
|
||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user