-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (38 loc) · 1.17 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
// express
const express = require('express');
const app = express();
const router = express.Router();
// mongoose
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
// inits
const path = require('path');
// const bodyParser = require('body-parser');
const cors = require('cors');
const rateLimit = require("express-rate-limit");
// imports
const config = require('./configs/constants');
const routes = require('./routes/baseRoutes')(router);
mongoose.connect(config.url,{ useNewUrlParser: true, useUnifiedTopology: true , useFindAndModify: false},(err)=>{
if(err){
console.log("Could not connect to the database" + err);
}else{
console.log("Connected to database ");
}
});
app.use(cors({ origin: 'https://localhost:3000' }));
app.use(express.json());
app.use(express.urlencoded());
// const limiter = rateLimit({
// windowMs: 15 * 60 * 1000,
// max: 100
// });
// app.use(limiter);
app.use(express.static(__dirname+'/public'));
app.use('/service',routes);
app.get('*',(req,res)=>{
res.sendFile(path.join(__dirname+'/public/index.html'));
});
app.listen(config.port, () => {
console.log(`Server started on port `, config.port);
});