-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (41 loc) · 2.06 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
// Set up ====================================================================================
var express = require('express'),
app = express(),
bodyParser = require('body-parser'),
pgConnectionString = process.env.RDS_HOSTNAME
? 'postgres://'
+ process.env.RDS_USERNAME
+ ':' + process.env.RDS_PASSWORD
+ '@' + process.env.RDS_HOSTNAME
+ ':' + process.env.RDS_PORT
+ '/' + process.env.RDS_DB_NAME
: 'postgres://localhost:5432/louisantonelli',
knex = require('knex')({ // Rivals legos for best childrens toy ever
client: 'pg',
connection: pgConnectionString,
searchPath: 'knex,public'
}),
passport = require('./app/passportSetup')(knex),
port = process.env.PORT || 3000;
// App configuration =========================================================================
app.set('view engine', 'ejs'); // Set ejs for templating
app.use('/bower_components', express.static(__dirname + '/bower_components')); // Bower components
app.use('/scripts', express.static(__dirname + '/scripts')); // Scripts
app.use('/public', express.static(__dirname + '/public')); // CSS
app.use(bodyParser.json()); // for parsing application/json
app.use(passport.initialize());
// Auth routes and middleware
app.use(require('./app/auth.js')(passport, knex));
// Site routes ===============================================================================
app.use(require('./app/routes.js')(knex));
// Api routes ================================================================================
app.use(require('./app/api.js')(knex));
// Start server ==============================================================================
app.listen(port, function () {
console.log(pgConnectionString);
console.log('Example app listening on port ' + port);
});
// Dev only ==================================================================================
var livereload = require('livereload');
var server = livereload.createServer();
server.watch([__dirname + "/public", __dirname + "/scripts"]);