-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
60 lines (49 loc) · 1.63 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
59
60
require('dotenv').config();
const cors = require('cors');
const express = require('express');
const expressJWT = require('express-jwt')
const favicon = require('serve-favicon');
const logger = require('morgan');
const path = require('path');
// App instance
const app = express();
// Set up middleware
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(cors());
app.use(express.json({limit: '50mb'}));
app.use(express.urlencoded({extended: false}));
// Controllers
// TODO: Ensure all auth routes are protected except for
// POST to /auth/login and /auth/signup
// Remember to pass the JWT_SECRET to ExpressJWT (it will break without it!)
// NOTE on ExpressJWT: The unless portion is only needed if you need exceptions
app.use('/auth', expressJWT({
secret: process.env.JWT_SECRET
}).unless({
path: [{
url: '/auth/login',
methods: ['POST']
},{
url: '/auth/signup',
methods: ['POST']
}
]
}), require('./controllers/auth'));
app.use('/sprints', expressJWT({
secret: process.env.JWT_SECRET
}), require('./controllers/sprints'))
app.use('/tasks', expressJWT({
secret: process.env.JWT_SECRET
}), require('./controllers/tasks'))
app.use('/users', expressJWT({
secret: process.env.JWT_SECRET
}), require('./controllers/users'))
// This is the catch-all route. Ideally you don't get here unless you made a mistake on your front-end
app.get('*', function(req, res, next) {
res.status(404).send({ message: 'Not Found' });
});
// Listen on specified PORT or default to 3000
app.listen((process.env.PORT || 3000), () => {
console.log(`server listening on port ${process.env.PORT || 3000}`);
});