OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package main | |
6 | |
7 import ( | |
8 "flag" | |
9 "net/http" | |
10 "path" | |
11 "strings" | |
12 ) | |
13 | |
14 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
| |
15 root string | |
16 } | |
17 | |
18 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
| |
19 return &skyHandler{root} | |
20 } | |
21 | |
22 func (handler *skyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
23 path := path.Join(handler.root, r.URL.Path) | |
24 if strings.HasSuffix(path, ".sky") { | |
25 w.Header().Set("Content-Type", "text/sky") | |
26 } | |
27 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
| |
28 } | |
29 | |
30 func main() { | |
31 var configuration = flag.String("t", "Release", "The target configuration (i .e. Release or Debug)") | |
32 flag.Parse() | |
33 | |
34 args := flag.Args() | |
35 root := args[0] | |
36 port := args[1] | |
37 | |
38 genRoot := path.Join(root, "out", *configuration, "gen") | |
39 | |
40 http.Handle("/", SkyHandler(root)) | |
41 http.Handle("/mojo/public/", http.StripPrefix("/mojo/public/", SkyHandler(pa th.Join(genRoot, "mojo", "public")))) | |
42 http.Handle("/mojo/services/", http.StripPrefix("/mojo/services/", SkyHandle r(path.Join(genRoot, "mojo", "services")))) | |
43 http.Handle("/sky/services/", http.StripPrefix("/sky/services/", SkyHandler( path.Join(genRoot, "sky", "services")))) | |
44 | |
45 http.ListenAndServe(":" + port, nil) | |
46 } | |
OLD | NEW |