-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathapp.js
76 lines (61 loc) · 1.84 KB
/
app.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
/*
* Copyright (C) <year> <copyright holder>
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the BSD license. See the LICENSE file for details.
*/
var express = require("express")
, read = require("read")
, pg = require("pg")
, cons = require("consolidate")
, routes = require("./routes")
, cookieParser = require("cookie-parser")
, path = require("path")
, app = express();
user_input = {
"usr": "",
"host": "",
"port": "",
"db": "",
"pwd": ""
};
var i = 2;
var argv = process.argv;
var new_len = argv.length - 1;
while(i < new_len) {
var arg = argv[i].replace("--", "");
if(arg in user_input) {
user_input[arg] = argv[i + 1];
} else {
throw Error("Could not parse user input: " + argv[i]);
}
i += 2;
}
runServer = function(err, pwd) {
var usr = user_input["usr"];
var url = "postgres://" + usr + ":" + pwd + "@" + user_input["host"] + "/" + user_input["db"] + "?ssl=false";
pg.connect(url, function(err, client, done) {
"use strict";
if(err) {
return console.error('error fetching client from pool', err);
}
app.engine("html", cons.swig);
app.set("view engine", "html");
app.use(express.static(path.join(__dirname, 'public')));
app.set("views", __dirname + "/views");
app.use(cookieParser());
var daos = require("./routes/daos");
var searchDAO = new daos.SearchDAO(client);
routes(app, client);
app.listen(8080);
console.log("Express server listening on port 8080");
});
}
if(!user_input["pwd"]) {
read({"prompt": "Password: ", "silent": true}, function(err, pwd) {
runServer(err, pwd);
});
} else {
runServer(null, user_input["pwd"]);
}