summaryrefslogtreecommitdiff
path: root/src/edit/main.go
blob: 3ddb2cdcc0073761e261daeb458a9703c3e82e41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package main

import (
	"net/http"
	"os"
	"util"
)

func ServeIndex(out http.ResponseWriter, in *http.Request) {
	if in.URL.Path != "/" {
		http.NotFound(out, in)
		return
	}
	http.Redirect(out, in, "/files/src/", http.StatusMovedPermanently)
}

var WWW = GitDir("/srv/http/edit.team4272.com/www.git")

func main() {
	socket, err := util.StreamListener(os.Args[1], os.Args[2])
	errcheck(err)
	http.Handle("/", util.SaneHTTPHandler{http.HandlerFunc(ServeIndex)})
	http.Handle("/static/", util.SaneHTTPHandler{http.StripPrefix("/static", http.FileServer(http.Dir("static")))})
	http.Handle("/files/", util.SaneHTTPHandler{http.StripPrefix("/files", http.HandlerFunc(ServeGit))})
	errcheck(http.Serve(socket, nil))
}