-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
71 lines (65 loc) · 2.25 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
'use strict';
require('dotenv').config();
const PORT = process.env.PORT || 3000;
const cookieSession = require('cookie-session');
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const cors = require('cors');
const utils = require('./helpers/utils');
const queries = require('./db/queries');
// Iniitalize express and routes
const app = express();
const { users, userId, friendsList } = require('./routes/users');
const { addFriend, removeFriend, acceptFriend, checkFriend } = require('./routes/friends');
const login = require('./routes/login');
const logout = require('./routes/logout');
const signup = require('./routes/signup');
const connect = require('./routes/connect');
const { goals, checkGoal, updateGoal } = require('./routes/goals');
const initialize = require('./routes/initialize');
const demo = require('./routes/demo');
const extension = require('./routes/extension');
const data = require('./routes/data');
const leaderboard = require('./routes/leaderboard');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use('/', express.static(path.join(__dirname, 'dist')));
app.use(
cookieSession({
name: 'session',
keys: [process.env.SESSION_KEY],
maxAge: 24 * 60 * 60 * 1000
})
);
// Catch-all routes for nonexistent paths
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'), function(err) {
if (err) {
res.status(500).send(err);
}
});
});
// Routes
app.post('/users', users);
app.post('/user/:userId', userId);
app.post('/user/:userId/data', data);
app.post('/user/:userId/friends', friendsList);
app.post('/friends/add_friend', addFriend);
app.post('/friends/accept_friend', acceptFriend);
app.post('/friends/remove_friend', removeFriend);
app.post('/friends/check_friend', checkFriend);
app.post('/login', login);
app.post('/logout', logout);
app.post('/signup', signup);
app.post('/connect', connect);
app.post('/goals', goals);
app.post('/goals/check', checkGoal);
app.post('/goals/update', updateGoal);
app.post('/initialize', initialize);
app.post('/extension', cors(), extension);
app.post('/demo', demo);
app.post('/leaderboard', leaderboard);
app.listen(PORT, () => {
console.log(`Server listening on ${PORT}`);
});