This repository has been archived by the owner on Jan 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
52 lines (41 loc) · 1.38 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
/* GENERAL IMPORTS */
import express from 'express';
import path from 'path';
import mongoose from 'mongoose';
import bodyParser from 'body-parser';
import passport from 'passport';
import helmet from 'helmet';
/* CONFIG IMPORT */
import config from './server/config';
/* ROUTES IMPORTS */
import index from './server/routes/index';
import auth from './server/routes/auth';
/* PASSPORT IMPORT */
import jwtLogin from './server/config/passport';
mongoose.Promise = global.Promise;
mongoose.connect(config.database);
const app = express();
app.use(helmet());
app.use(express.static(path.join(__dirname, 'client/build')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true,
}));
// Use cors instead ?
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization, Access-Control-Allow-Credentials');
res.header('Access-Control-Allow-Credentials', 'true');
next();
});
app.use(passport.initialize());
passport.use(jwtLogin);
app.use('/api', index);
app.use('/api/auth', auth);
/* redirect all unmatched routes to homepage */
app.get('*', (req, res) => {
res.sendFile(path.join(`${__dirname}/client/build/index.html`));
});
app.listen(config.port);
export default app;