OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # This helps you preview the apps and extensions docs. | 6 # This helps you preview the apps and extensions docs. |
7 # | 7 # |
8 # ./preview.py --help | 8 # ./preview.py --help |
9 # | 9 # |
10 # There are two modes: server- and render- mode. The default is server, in which | 10 # There are two modes: server- and render- mode. The default is server, in which |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 if not posixpath.abspath(self.path.lstrip('/')).startswith( | 46 if not posixpath.abspath(self.path.lstrip('/')).startswith( |
47 posixpath.abspath('')): | 47 posixpath.abspath('')): |
48 return | 48 return |
49 | 49 |
50 # Rewrite paths that would otherwise be served from app.yaml. | 50 # Rewrite paths that would otherwise be served from app.yaml. |
51 self.path = { | 51 self.path = { |
52 '/robots.txt': '../../server2/robots.txt', | 52 '/robots.txt': '../../server2/robots.txt', |
53 '/favicon.ico': '../../server2/chrome-32.ico', | 53 '/favicon.ico': '../../server2/chrome-32.ico', |
54 '/apple-touch-icon-precomposed.png': '../../server2/chrome-128.png' | 54 '/apple-touch-icon-precomposed.png': '../../server2/chrome-128.png' |
55 }.get(self.path, self.path) | 55 }.get(self.path, self.path) |
56 response = LocalRenderer.Render(self.path, headers=dict(self.headers)) | 56 response = LocalRenderer.Render( |
| 57 self.path, |
| 58 host='localhost:' + str(self.server.server_port), |
| 59 headers=dict(self.headers)) |
57 self.protocol_version = 'HTTP/1.1' | 60 self.protocol_version = 'HTTP/1.1' |
58 self.send_response(response.status) | 61 self.send_response(response.status) |
59 for k, v in response.headers.iteritems(): | 62 for k, v in response.headers.iteritems(): |
60 self.send_header(k, v) | 63 self.send_header(k, v) |
61 self.end_headers() | 64 self.end_headers() |
62 self.wfile.write(response.content.ToString()) | 65 self.wfile.write(response.content.ToString()) |
63 | 66 |
64 if __name__ == '__main__': | 67 if __name__ == '__main__': |
65 parser = optparse.OptionParser( | 68 parser = optparse.OptionParser( |
66 description='Runs a server to preview the extension documentation.', | 69 description='Runs a server to preview the extension documentation.', |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 print('') | 115 print('') |
113 print(' http://localhost:%s/apps/' % opts.port) | 116 print(' http://localhost:%s/apps/' % opts.port) |
114 print('') | 117 print('') |
115 | 118 |
116 logging.getLogger().setLevel(logging.INFO) | 119 logging.getLogger().setLevel(logging.INFO) |
117 server = HTTPServer(('', int(opts.port)), _RequestHandler) | 120 server = HTTPServer(('', int(opts.port)), _RequestHandler) |
118 try: | 121 try: |
119 server.serve_forever() | 122 server.serve_forever() |
120 finally: | 123 finally: |
121 server.socket.close() | 124 server.socket.close() |
OLD | NEW |