aboutsummaryrefslogtreecommitdiff
path: root/appengine.go
diff options
context:
space:
mode:
Diffstat (limited to 'appengine.go')
-rw-r--r--appengine.go49
1 files changed, 18 insertions, 31 deletions
diff --git a/appengine.go b/appengine.go
index 4767a2c..5db885b 100644
--- a/appengine.go
+++ b/appengine.go
@@ -2,56 +2,43 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build appengine
-
package main
import (
"bufio"
"bytes"
"io"
+ "log"
"net/http"
- "strings"
-
- "appengine"
+ "os"
_ "golang.org/x/tools/playground"
)
-const runUrl = "https://golang.org/compile"
-
-func init() {
- http.Handle("/lesson/", hstsHandler(lessonHandler))
- http.Handle("/", hstsHandler(rootHandler))
+func gaeMain() {
+ prepContent = gaePrepContent
+ socketAddr = gaeSocketAddr
if err := initTour(".", "HTTPTransport"); err != nil {
- panic(err)
+ log.Fatal(err)
}
-}
-func rootHandler(w http.ResponseWriter, r *http.Request) {
- c := appengine.NewContext(r)
- if err := renderUI(w); err != nil {
- c.Criticalf("UI render: %v", err)
- }
-}
+ http.Handle("/", hstsHandler(rootHandler))
+ http.Handle("/lesson/", hstsHandler(lessonHandler))
-func lessonHandler(w http.ResponseWriter, r *http.Request) {
- c := appengine.NewContext(r)
- lesson := strings.TrimPrefix(r.URL.Path, "/lesson/")
- if err := writeLesson(lesson, w); err != nil {
- if err == lessonNotFound {
- http.NotFound(w, r)
- } else {
- c.Criticalf("tour render: %v", err)
- }
+ registerStatic(".")
+
+ port := os.Getenv("PORT")
+ if port == "" {
+ port = "8080"
}
+ log.Fatal(http.ListenAndServe(":"+port, nil))
}
-// prepContent returns a Reader that produces the content from the given
+// gaePrepContent returns a Reader that produces the content from the given
// Reader, but strips the prefix "#appengine: " from each line. It also drops
// any non-blank like that follows a series of 1 or more lines with the prefix.
-func prepContent(in io.Reader) io.Reader {
+func gaePrepContent(in io.Reader) io.Reader {
var prefix = []byte("#appengine: ")
out, w := io.Pipe()
go func() {
@@ -84,9 +71,9 @@ func prepContent(in io.Reader) io.Reader {
return out
}
-// socketAddr returns the WebSocket handler address.
+// gaeSocketAddr returns the WebSocket handler address.
// The App Engine version does not provide a WebSocket handler.
-func socketAddr() string { return "" }
+func gaeSocketAddr() string { return "" }
// hstsHandler wraps an http.HandlerFunc such that it sets the HSTS header.
func hstsHandler(fn http.HandlerFunc) http.Handler {