-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
executable file
·58 lines (50 loc) · 1.42 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
50
51
52
53
54
55
56
57
58
'use strict';
var async = require('async');
var express = require('express');
var stormpath = require('express-stormpath');
var apiRoutes = require('./routes/api');
var privateRoutes = require('./routes/private');
var publicRoutes = require('./routes/public');
// Globals
var app = express();
// Application settings
app.set('view engine', 'jade');
app.set('views', './views');
app.locals.siteTitle = 'Billable API';
app.locals.stripePublishableKey = process.env.STRIPE_PUBLISHABLE_KEY;
// Middlewares
app.use('/static', express.static('./static', {
index: false,
redirect: false
}));
app.use('/static', express.static('./bower_components', {
index: false,
redirect: false
}));
app.use(stormpath.init(app, {
enableAccountVerification: true,
expandApiKeys: true,
expandCustomData: true,
redirectUrl: '/dashboard',
secretKey: 'very-long-and-very-secret-key',
postRegistrationHandler: function(account, req, res, next) {
async.parallel([
// Create an API key for this user.
function(cb) {
account.createApiKey(function(err, key) {
if (err) return cb(err);
cb();
});
}
], function(err) {
if (err) return next(err);
next();
});
}
}));
// Routes
app.use('/', publicRoutes);
app.use('/api', stormpath.apiAuthenticationRequired, apiRoutes);
app.use('/dashboard', stormpath.loginRequired, privateRoutes);
// Server
app.listen(process.env.PORT || 3000);