Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(781)

Unified Diff: third_party/WebKit/Source/devtools/hosted_mode/server.js

Issue 2167413002: DevTools: implement proxy server for hosted mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address CL feedback Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698