-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
77 lines (57 loc) · 2.67 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
77
//===============Modules=============================
var express = require('express');
firebase = require('firebase');
var bodyParser = require('body-parser');
var session = require('express-session');
var paginate = require('express-paginate');
var path = require('path');
var gcloud = require('google-cloud');
var ElasticSearch = require('elasticsearch');
var admin = require("firebase-admin"); //used for ServiceAccount's substitution with Firebase Admin
var app = express();
//-------------------------------------Files----------------------------------------------------------------------------
var api = require('./api');
var escutils = require('./escutils');
var PathMonitor = require('./lib/PathMonitor');
var SearchQueue = require('./lib/SearchQueue');
//-------------------------------- View engine setup---------------------------------------------------------------------
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
//------------------------------- Firebase initializtion -----------------------------------------------------------------
var config = {
apiKey: "***",
authDomain: "*your-project-id-here*.firebaseapp.com",
databaseURL: "https://*your-project-id*.firebaseio.com",
storageBucket: "***.appspot.com",
messagingSenderId: "**",
privateKey: "-----BEGIN PRIVATE KEY-----\n*****\n-----END PRIVATE KEY-----\n"
};
//set the session, the active interval
app.use(session({
secret: "H***h",
resave:true,
saveUninitialized:true,
cookie:{},
duration: 45 * 60 * 1000,
activeDuration: 15 * 60 * 1000
}));
firebase.initializeApp(config);
//---------------------------------------------------ElasticSearch Initialization ---------------------------------------
//create a new client
var esc = escutils.elasticSearchClient = new ElasticSearch.Client({
hosts: [
escutils.serverOptions //use the options already described in escutils.js and exported
]
});
//verify the connection
console.log('Connected to ElasticSearch host:'+ escutils.serverOptions.host +",on port: " + escutils.serverOptions.port);
PathMonitor.process(esc, escutils.paths, escutils.FB_PATH);
SearchQueue.init(esc, escutils.FB_REQ, escutils.FB_RES, escutils.CLEANUP_INTERVAL);
//-------------------------------------------------------------------------------------------------------------------------
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use('/api/search', api); //route prefix
//-------------------------------------Create the Server----------------------------------------------------------------------
app.listen(3000, function () {
console.log('Example app listening on port 3000');
});