forked from championswimmer/oneauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
68 lines (56 loc) · 1.91 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
/**
* Created by championswimmer on 08/03/17.
*/
const express = require('express')
, bodyParser = require('body-parser')
, session = require('express-session')
, passport = require('./passport/passporthandler')
, path = require('path')
, cookieParser = require('cookie-parser')
, exphbs = require('express-hbs');
const secrets = require('./secrets.json')
, config = require('./config')
, loginrouter = require('./routers/login')
, connectrouter = require('./routers/connect')
, logoutrouter = require('./routers/logoutrouter')
, signuprouter = require('./routers/signup')
, apirouter = require('./routers/api')
, oauthrouter = require('./routers/oauthrouter')
, pagerouter = require('./routers/pagerouter');
const app = express();
const redirectToHome = function (req, res, next) {
if (req.path == '/') {
return res.redirect('/users/me');
}
next();
};
app.engine('hbs', exphbs.express4({
partialsDir: path.join(__dirname, 'views/partials'),
layoutsDir: path.join(__dirname, 'views/layouts'),
defaultLayout: 'views/layouts/main.hbs',
}));
app.set('views', path.join(__dirname, 'views'));
app.set("view engine", "hbs");
app.use(express.static(path.join(__dirname, 'public_static')));
app.use(cookieParser(secrets.EXPRESS_SESSION_SECRET));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(session({
secret: secrets.EXPRESS_SESSION_SECRET,
resave: false,
saveUninitialized: false,
name: 'oneauth'
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(redirectToHome);
app.use('/login', loginrouter);
app.use('/connect', connectrouter);
app.use('/logout', logoutrouter);
app.use('/signup', signuprouter);
app.use('/api', apirouter);
app.use('/oauth', oauthrouter);
app.use('/', pagerouter);
app.listen(3838, function () {
console.log("Listening on " + config.SERVER_URL );
});