-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
63 lines (54 loc) · 1.57 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
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const firebase = require('firebase');
const octokit = require('@octokit/rest')();
const session = require('express-session');
const FirebaseStore = require('connect-session-firebase')(session);
const projectRouter = require('./routes/project');
const authRouter = require('./routes/auth');
const config = require('./util/config');
const bodyParser = require('body-parser');
// Initialize Express App
const app = express();
app.use(bodyParser.json());
const GH_KEY = process.env.GH_KEY;
const GH_SECRET = process.env.GH_SECRET;
// run Setup for Firebase and Octokit
const ref = firebase.initializeApp(config);
octokit.authenticate({
type: 'oauth',
key: GH_KEY,
secret: GH_SECRET
});
// Session Storage
app.use(session({
store: new FirebaseStore({
database: ref.database()
}),
secret: 'keyboard cat',
resave: true,
saveUninitialized: true
}));
// Routes
app.use('/api/project', projectRouter(octokit, firebase));
app.use('/api/auth', authRouter(GH_KEY, GH_SECRET));
// Middleware
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
// Serve FrontEnd build
app.use(express.static(path.join(__dirname, 'client/build')));
// Serve Sitemap
app.use(express.static('sitemap'));
// redirect all wildcard matches to landing page
app.use('*', (req, res) => {
res.redirect('/');
});
// catch 404
app.use((req, res) => {
res.redirect('/');
});
module.exports = app;