-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
76 lines (53 loc) · 2.08 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const express = require('express');
const connectDB = require('./config/db');
const path = require('path');
const cors = require('cors');
const fileUpload = require('express-fileupload');
const app = express();
app.use(fileUpload());
app.post('/upload',(req,res)=>{
if(req.files === null){
return res.status(400).json({msg:'No file upload'});
}
//if there is a request from a file the we will pull it
const file= req.files.file;
//take a file as oject and move it to the path that is given in parenthesis
file.mv(`${__dirname}/client/public/uploads/${file.name}`, err=>{
if(err){
console.error(err);
return res.status(500).send(err);
}
res.json({fileName: file.name, filePath:`/uploads/${file.name}`});
});
})
// Connect Database
connectDB();
// Init Middleware
app.use(express.json({ extended: false }));
app.use(cors());
// Define Routes
app.use('/api/users', require('./routes/users'));
app.use('/api/todoGroups', require('./routes/todoGroupRoutes'));
app.use('/api/todoTasks', require('./routes/todoTaskRoutes'));
app.use('/api/report', require('./routes/reportRoute'))
app.use('/api/messages', require('./routes/messageRoute'));
app.use('/api/auth', require('./routes/auth'));
app.use('/api/contacts', require('./routes/contacts'));
app.use('/api/events', require('./routes/events'));
app.use('/api/notes', require('./routes/noteRoute'));
app.use('/api/setting', require('./routes/settingRoute'));
app.use('/api/profile', require('./routes/profileRoutes'));
app.use('/api/invite', require('./routes/invite'));
app.use('/api/projects',require('./routes/projectRoute'));
app.use('/api/announcements',require('./routes/announcementRoute'));
// app.use('/allcontacts', require('./routes/contacts'));
// Serve static assets in production
if (process.env.NODE_ENV === 'production') {
// Set static folder
app.use(express.static('client/build'));
app.get('*', (req, res) =>
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
);
}
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server started on port ${PORT}`));