-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
116 lines (86 loc) · 3.02 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"use strict";
/**
* Module dependencies.
*/
var express = require('express');
var routes = require('./routes');
var http = require('http');
var path = require('path');
var mongoose = require('mongoose');
var _ = require('lodash');
//change to your setting
var config = {
displayName: "devlist update",
clientID: "xxxxxxxx.apps.googleusercontent.com",
clientSecret: "xxxxxxxx",
host: "localhost:5000",
oauth2callbackRoute : "/oauth2callback",
mongooseUrl : process.env.MONGOHQ_URL || "mongodb://glass-shopping-app:[email protected]:xxxxx/xxxxxxx"
};
if (process.env.NODE_ENV == "prod") {
config = _.extend(config, {
displayName: "shoppinglist update",
clientID: "xxxxxxxxx.apps.googleusercontent.com",
clientSecret: "xxxxxxxxxx",
host: "your_url.herokuapp.com"
});
}
var hostBaseUrl = "http://" + config.host;
//http://mongoosejs.com/docs/index.html
//https://devcenter.heroku.com/articles/mongohq#mongohq-web-tools
mongoose.connect(config.mongooseUrl);
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function callback () {
console.log("open db connection");
});
var app = express();
app.use(express.json());
app.use(express.urlencoded());
// all environments
app.set('port', process.env.PORT || 5000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
//called when app needs authentification
var authenticateApp = function(res, oauth2Client){
// generates a url that allows offline access and asks permissions
// for Mirror API scope.
var url = oauth2Client.generateAuthUrl({
access_type: 'offline',
//scope: 'https://www.googleapis.com/auth/glass.timeline https://www.googleapis.com/auth/glass.location'
scope: 'https://www.googleapis.com/auth/glass.timeline'
});
res.redirect(url);
};
var glassApi = require('./lib/glassMirrorApi')(config, authenticateApp);
//var shoppingListItem = require('./routes/shoppingListItem');
require("./models/shoppingListItem");
require("./models/location");
var genericSuccess = function(data) {
console.log('success', data);
};
var genericSuccessNoDataLog = function() {
console.log('success - plain');
};
var genericFailure = function(data) {
console.log('failure', data);
};
require("./routes/index")(app, glassApi, genericFailure, genericSuccess);
require("./routes/shoppingList")(app, glassApi, genericFailure, genericSuccess, hostBaseUrl);
require("./routes/shoppingListItem")(app, glassApi);
require("./routes/timeline")(app, glassApi, genericFailure, genericSuccess, hostBaseUrl);
require("./routes/location")(app, glassApi);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});