forked from stinkfloyd/standupstanddown-be
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
67 lines (59 loc) · 1.97 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
64
65
66
67
require("dotenv").config();
const express = require('express')
const path = require('path')
const cookieParser = require('cookie-parser')
const logger = require('morgan')
const cookieSession = require('cookie-session')
const passport = require('passport')
const passportSetup = require('./config/passport-setup')
// Routes
const indexRouter = require('./routes/index')
const authRouter = require('./routes/auth')
const usersRouter = require('./routes/users')
const teamsRouter = require('./routes/teams')
const teams_usersRouter = require('./routes/teams_users')
const user_teamsRouter = require('./routes/user_teams')
const sprintsRouter = require('./routes/sprints')
const standUpsRouter = require('./routes/standUps')
const app = express();
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "https://standup-fischer.herokuapp.com/");
res.header("Access-Control-Allow-Methods", "GET,POST,DELETE,PATCH,PUT");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.setHeader("Access-Control-Allow-Credentials", "true")
next();
});
// Middleware to initizilize passport & session
app.use(passport.initialize())
app.use(passport.session())
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/auth', authRouter)
app.use('/teams', teamsRouter)
app.use('/teams_users', teams_usersRouter)
app.use('/user_teams', user_teamsRouter)
app.use('/sprints', sprintsRouter)
app.use('/standups', standUpsRouter)
// Error Handling Below
app.use((err, req, res, next) => {
const status = err.status || 500
res.status(status).json({
error: {
status: err.status,
message: err.message
}
})
})
app.use((req, res, next) => {
res.status(404).json({
error: {
message: 'Not found'
}
})
})
module.exports = app;