Skip to content

Commit 8738006

Browse files
committed
Initial commit
0 parents  commit 8738006

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nom-debug.log

Diff for: npm-debug.log

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
0 info it worked if it ends with ok
2+
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
3+
2 info using [email protected]
4+
3 info using [email protected]
5+
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
6+
5 info lifecycle [email protected]~prestart: [email protected]
7+
6 silly lifecycle [email protected]~prestart: no script for prestart, continuing
8+
7 info lifecycle [email protected]~start: [email protected]
9+
8 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true
10+
9 verbose lifecycle [email protected]~start: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/adunkman/projects/time-over-http/node_modules/.bin:/Users/adunkman/.rbenv/shims:~/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin
11+
10 verbose lifecycle [email protected]~start: CWD: /Users/adunkman/projects/time-over-http
12+
11 silly lifecycle [email protected]~start: Args: [ '-c', 'node server.js' ]
13+
12 silly lifecycle [email protected]~start: Returned: code: 1 signal: null
14+
13 info lifecycle [email protected]~start: Failed to exec start script
15+
14 verbose stack Error: [email protected] start: `node server.js`
16+
14 verbose stack Exit status 1
17+
14 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:255:16)
18+
14 verbose stack at emitTwo (events.js:106:13)
19+
14 verbose stack at EventEmitter.emit (events.js:191:7)
20+
14 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
21+
14 verbose stack at emitTwo (events.js:106:13)
22+
14 verbose stack at ChildProcess.emit (events.js:191:7)
23+
14 verbose stack at maybeClose (internal/child_process.js:885:16)
24+
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
25+
15 verbose pkgid [email protected]
26+
16 verbose cwd /Users/adunkman/projects/time-over-http
27+
17 error Darwin 16.3.0
28+
18 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
29+
19 error node v7.1.0
30+
20 error npm v3.10.9
31+
21 error code ELIFECYCLE
32+
22 error [email protected] start: `node server.js`
33+
22 error Exit status 1
34+
23 error Failed at the [email protected] start script 'node server.js'.
35+
23 error Make sure you have the latest version of node.js and npm installed.
36+
23 error If you do, this is most likely a problem with the time-over-http package,
37+
23 error not with npm itself.
38+
23 error Tell the author that this fails on your system:
39+
23 error node server.js
40+
23 error You can get information on how to open an issue for this project with:
41+
23 error npm bugs time-over-http
42+
23 error Or if that isn't available, you can get their info via:
43+
23 error npm owner ls time-over-http
44+
23 error There is likely additional logging output above.
45+
24 verbose exit [ 1, true ]

Diff for: package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "time-over-http",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "server.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"start": "node server.js"
9+
},
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {}
13+
}

Diff for: public/index.html

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script>
5+
(() => {
6+
const client_start = new Date();
7+
8+
fetch("/endpoint").then((res) => {
9+
const client_end = new Date();
10+
const server_start = Date.parse(res.headers.get("Date"));
11+
const server_end = server_start;
12+
13+
const server_duration = server_end - server_start;
14+
const client_duration = client_end - client_start;
15+
const in_flight_time = client_duration - server_duration;
16+
const return_trip_time = in_flight_time / 2;
17+
18+
const corrected_client_end = new Date(server_end + return_trip_time);
19+
20+
console.log({
21+
client_now: client_end,
22+
server_now: corrected_client_end
23+
});
24+
});
25+
})();
26+
</script>
27+
</head>
28+
<body>
29+
</body>
30+
</html>

Diff for: server.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const fs = require("fs");
2+
const http = require("http");
3+
const path = require("path");
4+
5+
http.createServer((req, res) => {
6+
if (req.url === "/") {
7+
return sendHtml(res);
8+
}
9+
10+
if (req.url === "/endpoint") {
11+
res.writeHead(200);
12+
return res.end();
13+
}
14+
15+
res.writeHead(404);
16+
return res.end();
17+
}).listen(process.env.PORT || 3000, () => {
18+
console.log("booted");
19+
});
20+
21+
const sendHtml = (res) => {
22+
const file = "./public/index.html";
23+
const stat = fs.statSync(file);
24+
res.writeHead(200, {
25+
"Content-Type": "text/html",
26+
"Content-Length": stat.size
27+
});
28+
29+
fs.createReadStream(file).pipe(res);
30+
};

0 commit comments

Comments
 (0)