-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·97 lines (74 loc) · 2.27 KB
/
index.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
----------------------------------
Création d'un serveur sans Express
----------------------------------
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer(function(req, res) {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
res.end('<h1> Serveur mel Hello World\n</h1>');
});
server.listen(port, hostname, function () {
console.log(`Server running at http://${hostname}:${port}/`);
});
*/
var pipeline = require('./pipeline.js');
var HTTP_lib = require('./HTTP_lib.js');
var jsonfile = require('jsonfile');
var worker, downloader;
var bean, pdbFile, deterFile;
var bFront = false, bBack = false, bPPM = false;
/*
* Parsing a JSON file
*/
var parseConfig = function (fileName){
if (! fileName) console.log('ERROR in parseConfig : no fileName specified');
try { var obj = jsonfile.readFileSync(fileName); }
catch (err) { throw err; }
return obj;
};
// COMMAND LINE ARGUMENT PROCESSING
process.argv.forEach(function (val, index, array){
if (val === '--front') bFront = true; // test for front-end
if (val === '--back') bBack = true; // test for back-end
if (val === '--ppm') bPPM = true; // with PPM or not
if (val === '--conf') { // conf file : obligatory in every mode !!
if (! array[index + 1]) throw "usage : ";
bean = parseConfig(array[index + 1]);
}
if (val === '-pdb') { // pdb file
if (! array[index + 1]) throw "usage : ";
pdbFile = array[index + 1];
}
if (val === '-deter') { // detergent file
if (! array[index + 1]) throw 'usage : ';
deterFile = array[index + 1];
}
});
/********
FOR FRONT
********/
if (bFront) {
worker = pipeline.mimicCompute;
downloader = pipeline.mimicDownload;
/***********************
FOR BACK OR NORMAL MODES
***********************/
} else {
pipeline.start(bean);
worker = pipeline.compute;
downloader = pipeline.download; // not used in back-end mode
}
/*******
FOR BACK
*******/
if (bBack) {
HTTP_lib.backCompute(worker, pdbFile, deterFile, bPPM);
/************************
FOR FRONT OR NORMAL MODES
************************/
} else {
HTTP_lib.httpStart(worker, downloader, bean.scriptVariables.DOWNLOAD_DIR, bean.port, bean.dbEndpoints);
}