-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
82 lines (63 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const express = require('express');
const compression = require('compression');
const cookieParser = require('cookie-parser');
const dotenv = require('dotenv');
const passport = require('passport');
const Strategy = require('passport-veritone');
// init env vars
// --------------------------------
dotenv.config({ path: '.env.development' });
// settings
// --------------------------------
const settings = {
host: '0.0.0.0',
port: process.env.NODE_PORT || 9000,
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
callbackURL: process.env.CALLBACK_URL
};
// express app
// --------------------------------
const app = express();
// common app handlers
// --------------------------------
app.use(cookieParser());
app.use(compression());
// initalize passport
// --------------------------------
app.use(passport.initialize());
// allow static file serving
// --------------------------------
app.use('/', express.static('build'));
// middleware
// --------------------------------
app.use(function (req, res, next) {
next();
});
// Use the VeritoneStrategy within Passport.
passport.use(new Strategy({
clientID: settings.clientId,
clientSecret: settings.clientSecret,
callbackURL: settings.callbackURL,
}, function(accessToken, refreshToken, profile, done) {
return done(null, profile);
}));
app.get('/auth/veritone', passport.authenticate('veritone'));
app.get('/auth/veritone/callback',
passport.authenticate('veritone', { session: false }), (req, res) => {
res
.cookie('oauthToken', req.user.oauthToken, {
secure: false,
httpOnly: false
})
.redirect(302, 'http://local.veritone-sample-app.com:3000');
});
// start server
// --------------------------------
app.listen(settings.port, settings.host, err => {
if (err) {
console.log(err);
return;
}
console.log('🐬 App is listening at http://%s:%s', settings.host, settings.port);
});