forked from BIT-GDSC/GDSC-BIT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (53 loc) · 1.58 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
61
const express = require('express');
require('dotenv').config();
const bodyParser = require('body-parser');
const cors = require('cors');
const session = require('express-session');
const passport = require('passport');
const { v2 } = require("cloudinary");
const { readdirSync } = require('fs');
const path = require('path');
const connectDatabase = require('./api/config/connectDatabase.js');
const app = express();
app.use(express.json({ limit: '25mb' }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
app.use(bodyParser.json({ limit: '50mb' }));
app.use(cors());
app.use(session({
resave: false,
saveUninitialized: true,
secret: 'SECRET'
}));
app.use(passport.initialize());
app.use(passport.session());
v2.config({
cloud_name: process.env.CLOUDINARY_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
});
// Backend Routes
readdirSync("./api/routes").map((r) => app.use("/api/", require('./api/routes/' + r)));
app.get('/api', (req, res) => {
res.status(201).json({
success: true,
msg: "Server Running",
});
});
// Frontend Routes
app.use(express.static(path.resolve(__dirname, 'client', 'dist')))
app.get('*', (req, res) => {
res.sendFile(
path.resolve(__dirname, 'client', 'dist', 'index.html'),
function (err) {
if (err) {
res.status(500).send(err)
}
}
)
});
const PORT = process.env.PORT || 5001;
connectDatabase().then(() => {
app.listen(PORT, () => {
console.log(`Connected to PORT => ${PORT}`);
})
});