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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
(Empty)
1 var fs = require("fs");
2 var http = require("http");
3 var path = require("path");
4 var parseUrl = require("url").parse;
5
6 var protocolFilesProxy = require("./protocol_files_proxy.js");
7
8 var port = parseInt(process.env.PORT, 10) || 9999;
lushnikov 2016/07/22 02:56:21 || 8090; (the default port atm)
chenwilliam 2016/07/22 17:35:25 OK, I can change it. I got the 9999 from the Chrom
9
10 http.createServer(requestHandler).listen(port);
11 protocolFilesProxy.loadCache();
12 console.log("Starting hosted mode server at:\n http://localhost:" + port);
13
14 function requestHandler(request, response)
15 {
16 var url = parseUrl(request.url).pathname;
17
18 if (url === "/front_end/InspectorBackendCommands.js") {
19 sendResponse(200, " ");
lushnikov 2016/07/22 02:56:21 can we pass just "" here?
chenwilliam 2016/07/22 17:35:25 I initially tried it with an empty string but then
20 return;
21 }
22
23 if (protocolFilesProxy.protocolFiles.indexOf(url) > -1) {
24 protocolFilesProxy.getProtocolFile(url)
25 .then(data => sendResponse(200, data))
26 .catch(err => console.log(`Error getting ${protocolFile}:`, err));
27 return;
28 }
29
30 var filePath = path.join(process.cwd(), url);
31 fs.exists(filePath, fsExistsCallback);
32
33 function fsExistsCallback(fileExists)
34 {
35 if (!fileExists) {
36 sendResponse(404, "404 - File not found");
37 return;
38 }
39 fs.readFile(filePath, "binary", readFileCallback);
40 }
41
42 function readFileCallback(err, file)
43 {
44 if (err) {
45 sendResponse(500, `500 - Can't read file: ${err}`);
46 return;
47 }
48 sendResponse(200, file);
49 }
50
51 function sendResponse(statusCode, data)
52 {
53 response.writeHead(statusCode);
54 response.write(data, "binary");
55 response.end();
56 }
57 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698