| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package main | 5 package main |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "flag" | 8 "flag" |
| 9 "fmt" | 9 "fmt" |
| 10 "io/ioutil" | 10 "io/ioutil" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 func skyHandler(root string) http.Handler { | 22 func skyHandler(root string) http.Handler { |
| 23 return &skyHandlerRoot{root} | 23 return &skyHandlerRoot{root} |
| 24 } | 24 } |
| 25 | 25 |
| 26 func (handler *skyHandlerRoot) ServeHTTP(w http.ResponseWriter, r *http.Request)
{ | 26 func (handler *skyHandlerRoot) ServeHTTP(w http.ResponseWriter, r *http.Request)
{ |
| 27 path := path.Join(handler.root, r.URL.Path) | 27 path := path.Join(handler.root, r.URL.Path) |
| 28 if strings.HasSuffix(path, ".sky") { | 28 if strings.HasSuffix(path, ".sky") { |
| 29 w.Header().Set("Content-Type", "text/sky") | 29 w.Header().Set("Content-Type", "text/sky") |
| 30 } | 30 } |
| 31 w.Header().Set("Cache-Control", "no-cache") |
| 31 http.ServeFile(w, r, path) | 32 http.ServeFile(w, r, path) |
| 32 } | 33 } |
| 33 | 34 |
| 34 func usage() { | 35 func usage() { |
| 35 fmt.Fprintf(os.Stderr, "Usage: sky_server [flags] MOJO_SRC_ROOT PORT\n\n") | 36 fmt.Fprintf(os.Stderr, "Usage: sky_server [flags] MOJO_SRC_ROOT PORT\n\n") |
| 36 fmt.Fprintf(os.Stderr, "launches a basic http server with mappings into the\
n") | 37 fmt.Fprintf(os.Stderr, "launches a basic http server with mappings into the\
n") |
| 37 fmt.Fprintf(os.Stderr, "mojo repository for framework/service paths.\n") | 38 fmt.Fprintf(os.Stderr, "mojo repository for framework/service paths.\n") |
| 38 fmt.Fprintf(os.Stderr, "[flags] MUST be before arguments, because go:flag.\n
\n") | 39 fmt.Fprintf(os.Stderr, "[flags] MUST be before arguments, because go:flag.\n
\n") |
| 39 flag.PrintDefaults() | 40 flag.PrintDefaults() |
| 40 os.Exit(2) | 41 os.Exit(2) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 defer r.Body.Close() | 78 defer r.Body.Close() |
| 78 body, _ := ioutil.ReadAll(r.Body) | 79 body, _ := ioutil.ReadAll(r.Body) |
| 79 w.Write(body) | 80 w.Write(body) |
| 80 }) | 81 }) |
| 81 | 82 |
| 82 addMapping("/gen/", genRoot) | 83 addMapping("/gen/", genRoot) |
| 83 addMapping("/packages/", packageRoot) | 84 addMapping("/packages/", packageRoot) |
| 84 | 85 |
| 85 http.ListenAndServe(":" + port, nil) | 86 http.ListenAndServe(":" + port, nil) |
| 86 } | 87 } |
| OLD | NEW |