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

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: Address CL feedback Created 4 years, 4 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 // 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698