-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
84 lines (55 loc) · 2.53 KB
/
server.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
/* Copyright 2016-2017 University of Pittsburgh
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http:www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
// SET UP
var _dirname = "/home/yin2/dbmi-annotator/";
var config = require('./config/config');
var pg = require('pg');
// Load packages
fs = require('fs');
var express = require('express');
var passport = require('passport');
var flash = require('connect-flash');
var morgan = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var expressValidator = require('express-validator');
// bring sequelize in
var Sequelize = require('sequelize');
var sequelize = new Sequelize(config.postgres, {dialect:'postgres', define:{freezeTableName:true, timestamps: false}});
// Initialize postgres DB schema - dbmiannotator
var client = new pg.Client(config.postgres);
var schemasql = fs.readFileSync('./db-schema/rdb-postgres-schema.sql').toString();
var initsql = fs.readFileSync('./db-schema/rdb-postgres-initial.sql').toString();
client.query(schemasql);
// model initialize
var user = require('./models/user')(sequelize, Sequelize);
//var plugin = require('./models/plugin')(sequelize, Sequelize);
// user.sync();
// plugin.sync();
var app = express();
app.use(morgan('dev')); // log every request to the console
app.use(cookieParser()); // read cookies (needed for auth)
app.use(bodyParser()); // get information from html forms
app.use(expressValidator());
app.use(express.static('public'));
app.set('view engine', 'ejs');
// required for passport
app.use(session({ secret: 'dbmi2016'}));
//app.use(session({ secret: 'dbmi2016', cookie: {expires: new Date(Date.now() + 3600000)}})); // session secret
// maxAge: new Date(Date.now() + 3600000) cause session expire one hr after server start
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash());
require('./config/passport')(passport, user);
require('./controllers/routes')(app, passport);
require('./controllers/pdf-image-extract')(app);
app.listen(config.annotator.port);