-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
80 lines (65 loc) · 2.39 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
77
78
79
80
const path = require("path");
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const passport = require('passport');
const admin = require('./routes/api/admin');
const user = require('./routes/api/user');
const location = require('./routes/api/location');
const policestation = require('./routes/api/policestation');
const passbooking = require('./routes/api/passbooking');
const survey = require('./routes/api/survey');
const fileUpload = require('express-fileupload');
// default options
require('dotenv').load();
const app = express();
app.use(fileUpload());
app.use(express.static('*'));
//Body Parser Middleware
app.use(bodyParser.json({limit: "50mb"}));
app.use(bodyParser.urlencoded({limit: "50mb", extended: true, parameterLimit:50000}));
//DB Config & connection
const db = require('./config/keys').mongoURI;
mongoose
.connect(db)
.then(()=>console.log('MongoDB Connected'))
.catch(err => console.log(err));
//Passport Middleware
app.use(passport.initialize());
//Passport Config
require('./config/passport')(passport);
//Use Routes
app.use('/api/admin', admin);
app.use('/api/user', user);
app.use('/api/location', location);
app.use('/api/policestation', policestation);
app.use('/api/passbooking', passbooking);
app.use('/api/survey', survey);
// app.post('/upload', function(req, res) {
// if (!req.files)
// return res.status(400).send('No files were uploaded.');
// let sampleFile = req.files.file;
// sampleFile.mv(`uploads/${req.body.filename}`, async function(err) {
// if (err) {
// return res.status(500).send(err);
// }
// await cloudinary.uploader.upload(`uploads/${req.body.filename}`, {"crop":"limit","tags":"category","width":300,"height":200},
// function(error,result) {
// console.log("res",result)
// res.json(result.url);
// });
// //cloudinary.uploader.upload("uploads/writing.png", {"crop":"limit","tags":"samples","width":3000,"height":2000}, function(result) { console.log(result) });
// });
// })
app.get('/*', function(req, res) {
res.sendFile(path.join(__dirname, '../../dist/index.html'), function(err) {
if (err) {
res.status(500).send(err)
}
})
})
//Server port & configuration
const port = process.env.PORT || 5000;
app.listen(port,()=> {
console.log(`Server is Listening on ${port}`);
});