-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
49 lines (42 loc) · 1.72 KB
/
index.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
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
global.io = io;
var querystring = require('querystring');
var cookieParser = require('cookie-parser');
var path = require('path');
global.appRoot = path.resolve(__dirname);
// my app stuff
require(__dirname + '/config/passport.js')
var innorow = require(__dirname + '/lib/innorow.js')
// use cookies
app.use(cookieParser());
// prepare server
app.use('/js', express.static(__dirname + '/node_modules/bootstrap/dist/js')); // redirect bootstrap JS
app.use('/js', express.static(__dirname + '/node_modules/jquery/dist')); // redirect JS jQuery
app.use('/js', express.static(__dirname + '/node_modules/react/dist')); // redirect react JS
app.use('/js', express.static(__dirname + '/node_modules/react-dom/dist')); // redirect react-dom JS
app.use('/css', express.static(__dirname + '/node_modules/bootstrap/dist/css')); // redirect CSS bootstrap
// serve static files
app.use(express.static(__dirname + '/public'));
// Here are the routes
app.get('/', function(req, res){
if (runkeeperAccessToken) {
res.cookie('runkeeperAccessToken' , runkeeperAccessToken);
} else if (req.cookies.runkeeperAccessToken){
runkeeperAccessToken = req.cookies.runkeeperAccessToken;
} else {
return res.redirect("/auth/runkeeper");
}
res.sendfile((__dirname + '/app/views/index.html'));
});
app.get('/auth/runkeeper', passport.authenticate('runkeeper'));
app.get('/auth/runkeeper/callback', passport.authenticate('runkeeper', {failureRedirect: '/' }),
function(req, res) {
// Successful authentication, redirect home.
res.redirect('/');
});
http.listen(3000, function(){
console.log('listening on *:3000');
});