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) |
+} |