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
25
main.go
25
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,
|
||||
|
@ -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