| Index: third_party/WebKit/Source/devtools/hosted_mode/server.js
|
| diff --git a/third_party/WebKit/Source/devtools/hosted_mode/server.js b/third_party/WebKit/Source/devtools/hosted_mode/server.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1bf2161ea4b441aa25e3575c1afa4b718b1c00c8
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/devtools/hosted_mode/server.js
|
| @@ -0,0 +1,56 @@
|
| +// Copyright (c) 2016 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.
|
| +
|
| +var fs = require("fs");
|
| +var http = require("http");
|
| +var path = require("path");
|
| +var parseUrl = require("url").parse;
|
| +
|
| +var protocolFilesProxy = require("./protocol_files_proxy.js");
|
| +
|
| +var port = parseInt(process.env.PORT, 10) || 8090;
|
| +
|
| +http.createServer(requestHandler).listen(port);
|
| +console.log("Starting hosted mode server at:\n http://localhost:" + port);
|
| +
|
| +function requestHandler(request, response)
|
| +{
|
| + var filePath = parseUrl(request.url).pathname;
|
| +
|
| + if (filePath === "/front_end/InspectorBackendCommands.js") {
|
| + sendResponse(200, " ");
|
| + return;
|
| + }
|
| +
|
| + if (protocolFilesProxy.proxy(filePath, sendResponse))
|
| + return;
|
| +
|
| + var absoluteFilePath = path.join(process.cwd(), filePath);
|
| + fs.exists(absoluteFilePath, fsExistsCallback);
|
| +
|
| + function fsExistsCallback(fileExists)
|
| + {
|
| + if (!fileExists) {
|
| + sendResponse(404, "404 - File not found");
|
| + return;
|
| + }
|
| + fs.readFile(absoluteFilePath, "binary", readFileCallback);
|
| + }
|
| +
|
| + function readFileCallback(err, file)
|
| + {
|
| + if (err) {
|
| + sendResponse(500, `500 - Can't read file: ${err}`);
|
| + return;
|
| + }
|
| + sendResponse(200, file);
|
| + }
|
| +
|
| + function sendResponse(statusCode, data)
|
| + {
|
| + response.writeHead(statusCode);
|
| + response.write(data, "binary");
|
| + response.end();
|
| + }
|
| +}
|
|
|