forked from flickr/yakbak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·36 lines (30 loc) · 1010 Bytes
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env node
// Copyright 2019 SmugMug, Inc.
// Licensed under the terms of the MIT license. Please see LICENSE file in the project root for terms.
/* eslint no-console:"off" */
var http = require('http');
var path = require('path');
var curl = require('./lib/curl');
var PORT = 3000;
try {
if (!process.argv[2]) {
throw new Error('file is required');
}
http.createServer(require(path.resolve(process.argv[2])))
.on('connection', function (socket) {
console.log('* Connection from %s port %s',
socket.remoteAddress, socket.remotePort);
socket.on('close', function () {
console.log('* Connection closed');
});
}).on('request', function (req, res) {
console.log(curl.request(req));
console.log(curl.response(req, res));
}).listen(PORT, function () {
console.log('Server listening on port %d', this.address().port);
});
} catch (err) {
console.warn('%s: %s', err.name, err.message);
console.warn('Usage: yakbak <file>');
process.exit(1);
}