-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
53 lines (38 loc) · 1.12 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
const express = require('express');
const cors = require('cors');
const mongoose = require('mongoose');
const path = require('path');
require('dotenv').config();
//App Cofig
const app = express();
const port = process.env.PORT || 5000;
// Cors
const corsOptions = {
origin: process.env.ALLOWED_CLIENTS.split(',')
}
//Middlewares
app.use(cors())
app.use(express.json());
app.use(express.static('public'));
//DB config
const connection_url = process.env.ATLAS_URI;
mongoose.connect(connection_url, {
useNewUrlParser: true,
useUnifiedTopology: true
}
);
const connection = mongoose.connection;
connection.once('open', () => {
console.log("MongoDB database connection established successfully");
})
const filesRoute = require('./routes/files');
const showRoute = require('./routes/show');
const downloadRoute = require('./routes/downloads')
app.set('views', path.join(__dirname, '/views'));
app.set('view engine', 'ejs');
app.use('/api/files', filesRoute);
app.use('/files', showRoute)
app.use('/files/download', downloadRoute);
app.listen(port, () => {
console.log(`Server is running on port: ${port}`);
});