| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2016 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 var fs = require("fs"); |
| 6 var http = require("http"); |
| 7 var path = require("path"); |
| 8 var parseUrl = require("url").parse; |
| 9 |
| 10 var protocolFilesProxy = require("./protocol_files_proxy.js"); |
| 11 |
| 12 var port = parseInt(process.env.PORT, 10) || 8090; |
| 13 |
| 14 http.createServer(requestHandler).listen(port); |
| 15 console.log("Starting hosted mode server at:\n http://localhost:" + port); |
| 16 |
| 17 function requestHandler(request, response) |
| 18 { |
| 19 var filePath = parseUrl(request.url).pathname; |
| 20 |
| 21 if (filePath === "/front_end/InspectorBackendCommands.js") { |
| 22 sendResponse(200, " "); |
| 23 return; |
| 24 } |
| 25 |
| 26 if (protocolFilesProxy.proxy(filePath, sendResponse)) |
| 27 return; |
| 28 |
| 29 var absoluteFilePath = path.join(process.cwd(), filePath); |
| 30 fs.exists(absoluteFilePath, fsExistsCallback); |
| 31 |
| 32 function fsExistsCallback(fileExists) |
| 33 { |
| 34 if (!fileExists) { |
| 35 sendResponse(404, "404 - File not found"); |
| 36 return; |
| 37 } |
| 38 fs.readFile(absoluteFilePath, "binary", readFileCallback); |
| 39 } |
| 40 |
| 41 function readFileCallback(err, file) |
| 42 { |
| 43 if (err) { |
| 44 sendResponse(500, `500 - Can't read file: ${err}`); |
| 45 return; |
| 46 } |
| 47 sendResponse(200, file); |
| 48 } |
| 49 |
| 50 function sendResponse(statusCode, data) |
| 51 { |
| 52 response.writeHead(statusCode); |
| 53 response.write(data, "binary"); |
| 54 response.end(); |
| 55 } |
| 56 } |
| OLD | NEW |