Skip to content

Commit 263b028

Browse files
committed
remove profiler-related stuff from web/server.js (cherry-picked from 3f280cd)
1 parent aa80cc4 commit 263b028

File tree

1 file changed

+0
-92
lines changed

1 file changed

+0
-92
lines changed

web/server.js

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -82,88 +82,6 @@ function serveFile(response, uri, filename) {
8282
});
8383
}
8484

85-
function saveProfile(request, response) {
86-
var profileDir = "web/.profile";
87-
88-
response.setHeader("Access-Control-Allow-Origin", "*");
89-
response.setHeader("Access-Control-Allow-Methods", "POST,PUT,GET,OPTIONS");
90-
response.setHeader("Access-Control-Allow-Headers", "Content-Type,*");
91-
if (request.method != "POST" || request.method == "PUT") {
92-
response.end();
93-
return;
94-
}
95-
96-
function twodigits(s) {
97-
s = s.toString();
98-
while (s.length < 2) {
99-
s = "0" + s;
100-
}
101-
return s;
102-
}
103-
function YYYYmmddHHMMSS() {
104-
var d = new Date();
105-
return d.getFullYear() + '-' +
106-
twodigits(d.getMonth() + 1) + '-' +
107-
twodigits(d.getDate()) + '-' +
108-
twodigits(d.getHours()) +
109-
twodigits(d.getMinutes()) +
110-
twodigits(d.getSeconds());
111-
}
112-
113-
var body = "";
114-
// accumulate all data
115-
request.on("data", function (data) {
116-
body += data;
117-
});
118-
request.on("end", function () {
119-
// parse as JSON
120-
try {
121-
var json = JSON.parse(body);
122-
} catch (e) {
123-
response.writeHead(400, "Bad Request", {
124-
"Content-Type": "text/plain"
125-
});
126-
response.write("POST data is corrupt: " + e.toString());
127-
response.end();
128-
return;
129-
}
130-
// save
131-
try {
132-
fs.mkdirSync(profileDir);
133-
} catch (e) {
134-
// FIXME ignore EEXIST only, but how?
135-
}
136-
var id = YYYYmmddHHMMSS();
137-
138-
fs.writeFileSync(profileDir + "/" + id + ".json", JSON.stringify(json));
139-
// send response
140-
response.writeHead(200, "OK", {
141-
"Location" : "http://" + request.headers.host + "/web/profiler.html?" + id,
142-
"Content-Type": "text/plain"
143-
});
144-
response.write("saved profile at http://" + request.headers.host + "/web/profiler.html?" + id);
145-
response.end();
146-
147-
console.info("[I] saved profile at http://" + request.headers.host + "/web/profiler.html?" + id);
148-
});
149-
}
150-
151-
function listProfileResults(request, response) {
152-
var results = fs.readdirSync("web/.profile").filter(function (file) {
153-
return /\d{4}-\d{2}-\d{2}-\d{4}/.test(file);
154-
}).map(function (file) {
155-
return file.replace(/\.\w+$/, "");
156-
}).sort(function (a, b) {
157-
return b.localeCompare(a)
158-
});
159-
160-
response.writeHead(200, "OK", {
161-
"Content-Type": "application/json"
162-
});
163-
response.write(JSON.stringify(results), "utf8");
164-
response.end();
165-
}
166-
16785
function main(args) {
16886
var port = args[0] || "5000";
16987

@@ -178,16 +96,6 @@ function main(args) {
17896
return;
17997
}
18098

181-
// profiler stuff
182-
if (/^\/post-profile\/?$/.test(uri)) {
183-
return saveProfile(request, response);
184-
}
185-
else if (/\/\.profile\/results\.json$/.test(uri)) {
186-
return listProfileResults(request, response);
187-
}
188-
189-
var filename = path.join(process.cwd(), uri);
190-
19199
if(/(?:\.html|\/)$/.test(filename)) {
192100
child_process.execFile(
193101
"perl", ["web/build.pl"],

0 commit comments

Comments
 (0)