Add home page
This commit is contained in:
parent
625612a282
commit
6967b5606a
|
@ -2,5 +2,7 @@
|
|||
"listen": "0.0.0.0:1965",
|
||||
"cert_path": "cert.pem",
|
||||
"key_path": "key.rsa",
|
||||
"base_url": "https://mamot.fr"
|
||||
"base_url": "https://mamot.fr",
|
||||
"title": "MastoGem",
|
||||
"home_message": "Welcome on MastoGem, a Mastodon proxy for Gemini.\\nYou can view the last 20 toots of a Mastodon account by providing its id, for example:\\n=> gemini://localhost/310515 My Mastodon account"
|
||||
}
|
||||
|
|
29
server.go
29
server.go
|
@ -24,10 +24,12 @@ type Blog struct {
|
|||
}
|
||||
|
||||
type Config struct {
|
||||
Listen string `json:"listen"`
|
||||
CertPath string `json:"cert_path"`
|
||||
KeyPath string `json:"key_path"`
|
||||
BaseURL string `json:"base_url"`
|
||||
Listen string `json:"listen"`
|
||||
CertPath string `json:"cert_path"`
|
||||
KeyPath string `json:"key_path"`
|
||||
BaseURL string `json:"base_url"`
|
||||
Title string `json:"title"`
|
||||
HomeMessage string `json:"home_message"`
|
||||
}
|
||||
|
||||
type Account struct {
|
||||
|
@ -43,7 +45,7 @@ func main() {
|
|||
log.Println("Server successfully started")
|
||||
log.Println("Server is listening at " + config.Listen)
|
||||
|
||||
serve(listener, config.BaseURL)
|
||||
serve(listener, config.BaseURL, config.Title, config.HomeMessage)
|
||||
}
|
||||
|
||||
func getConfig() Config {
|
||||
|
@ -56,6 +58,8 @@ func getConfig() Config {
|
|||
CertPath: "cert.pem",
|
||||
KeyPath: "key.rsa",
|
||||
BaseURL: "https://mamot.fr",
|
||||
Title: "MastoGem",
|
||||
HomeMessage: "Welcome on MastoGem, this is a Mastodon proxy for Gemini. You can view the last 20 toots of a Mastodon account by providing its ID.",
|
||||
}
|
||||
|
||||
return config
|
||||
|
@ -93,14 +97,14 @@ func listen(address, certFile, keyFile string) net.Listener {
|
|||
return listener
|
||||
}
|
||||
|
||||
func serve(listener net.Listener, baseURL string) {
|
||||
func serve(listener net.Listener, baseURL, title, home_message string) {
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
go handleConn(conn.(*tls.Conn), baseURL)
|
||||
go handleConn(conn.(*tls.Conn), baseURL, title, home_message)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,7 +136,7 @@ func getPath(conn *tls.Conn) (string, error) {
|
|||
return parsedURL.Path, nil
|
||||
}
|
||||
|
||||
func handleConn(conn *tls.Conn, baseURL string) {
|
||||
func handleConn(conn *tls.Conn, baseURL, title, home_message string) {
|
||||
defer conn.Close()
|
||||
|
||||
path, err := getPath(conn)
|
||||
|
@ -148,6 +152,15 @@ func handleConn(conn *tls.Conn, baseURL string) {
|
|||
|
||||
path = path[1:]
|
||||
|
||||
if path == "" {
|
||||
_, err = fmt.Fprintf(conn, "20 text/gemini\r\n# " + title + "\n\n" + home_message)
|
||||
if err != nil {
|
||||
log.Println("send error: %s", err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
_, err = strconv.ParseUint(path, 10, 64)
|
||||
if err != nil {
|
||||
log.Println("invalid request: %s", err)
|
||||
|
|
Loading…
Reference in New Issue