Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(673)

Unified Diff: sky/tools/skygo/sky_server.go

Issue 746373002: Convert sky_server over to a go-based http server. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: no check in binary Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/tools/skygo/README ('k') | sky/tools/skygo/sky_server.sha1 » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/tools/skygo/sky_server.go
diff --git a/sky/tools/skygo/sky_server.go b/sky/tools/skygo/sky_server.go
new file mode 100644
index 0000000000000000000000000000000000000000..3bedc3ec625f1da53dec8dfbf7af74fe5f72c9a5
--- /dev/null
+++ b/sky/tools/skygo/sky_server.go
@@ -0,0 +1,46 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package main
+
+import (
+ "flag"
+ "net/http"
+ "path"
+ "strings"
+)
+
+type skyHandler struct {
jamesr 2014/12/04 22:15:08 if the only state you need is a string, you can ju
ojan 2014/12/04 23:57:20 I think my go-fu is not quite up to this. I tried
+ root string
+}
+
+func SkyHandler(root string) http.Handler {
jamesr 2014/12/04 22:15:08 don't need to export this, so lowercase (although
ojan 2014/12/04 23:57:20 done
+ return &skyHandler{root}
+}
+
+func (handler *skyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ path := path.Join(handler.root, r.URL.Path)
+ if strings.HasSuffix(path, ".sky") {
+ w.Header().Set("Content-Type", "text/sky")
+ }
+ http.ServeFile(w, r, path)
esprehn 2014/12/03 02:26:43 Does this serve images with the right mime?
ojan 2014/12/03 02:54:19 Yes
+}
+
+func main() {
+ var configuration = flag.String("t", "Release", "The target configuration (i.e. Release or Debug)")
+ flag.Parse()
+
+ args := flag.Args()
+ root := args[0]
+ port := args[1]
+
+ genRoot := path.Join(root, "out", *configuration, "gen")
+
+ http.Handle("/", SkyHandler(root))
+ http.Handle("/mojo/public/", http.StripPrefix("/mojo/public/", SkyHandler(path.Join(genRoot, "mojo", "public"))))
+ http.Handle("/mojo/services/", http.StripPrefix("/mojo/services/", SkyHandler(path.Join(genRoot, "mojo", "services"))))
+ http.Handle("/sky/services/", http.StripPrefix("/sky/services/", SkyHandler(path.Join(genRoot, "sky", "services"))))
+
+ http.ListenAndServe(":" + port, nil)
+}
« no previous file with comments | « sky/tools/skygo/README ('k') | sky/tools/skygo/sky_server.sha1 » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698