-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (41 loc) · 973 Bytes
/
index.js
File metadata and controls
55 lines (41 loc) · 973 Bytes
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
const express = require('express');
const app = express();
const authenticate = require('./lib/authenticator');
const reposApi = require('./lib/api')
const program = require('commander');
const fs = require('fs');
/**
* Command line app management
*/
program
.version('0.0.1')
.usage('<keys_file>')
.parse(process.argv);
if(program.args.length!==1){
program.outputHelp();
process.exit(0);
}
/**
* retrieving of api keys
*/
let keysFile;
const fileError = new Error('Cannot read keys file at: ' + program.args[0]);
try {
keysFile = fs.readFileSync(program.args[0], {encoding: 'utf8'});
}catch(e){
return console.error(fileError);
}
if(!keysFile){
console.error(fileError);
return process.exit(1);
}
/**
* Serving the api
*/
const keys = keysFile.split('\n');
app.use(authenticate(keys));
app.use('/repos',reposApi);
app.listen(3000, function () {
console.log('Githubber listening on port 3000!');
});