-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
60 lines (50 loc) · 2.03 KB
/
index.js
File metadata and controls
60 lines (50 loc) · 2.03 KB
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
const express=require('express');
const app=express();
const studentRoutes = require('./routes/students.routes');
const connectDB = require('./config/students.database');
const { MulterError } = require('multer');
const cors = require('cors');
const path = require('path');
const auth = require('./middleware/auth');
const userRoutes = require('./routes/users.routes');
const rateLimit = require('express-rate-limit');
const helmet = require('helmet');
const twilio = require('twilio')
connectDB();
const limiter = rateLimit({
windowMs: 1000*60,
max: 100,
message: 'Too many request from this IP, please try again later.'
});
app.use(express.urlencoded({extended: false}));
app.use(express.json());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/uploads', express.static(path.join(__dirname,'uploads')));
app.use(cors({
origgin: [
"http://localhost:3000",
"https://basic-api-sandy.vercel.app/",
"https://basic-56ioauzuo-madhukarkug25cs-9202s-projects.vercel.app/",
]
}));
//app.use(helmet()); //mostly used in ONLINE live server as can create testing problem.
app.get('/api/health',(req,res)=> res.json({HealthStatus: 'Ok', message: 'Server is Up and Running on PORT NO: 3000'}));
app.get('/',(req,res)=> res.render('index'));
app.get('/login',(req,res)=> res.sendFile(path.join(__dirname, 'public', 'login.html')));
app.get('/register',(req,res)=> res.sendFile(path.join(__dirname, 'public', 'register.html')));
app.get('/new',(req,res)=> res.sendFile(path.join(__dirname, 'public', 'new.html')));
app.use(limiter);
app.use('/api/users', userRoutes);
app.use(auth);
app.use('/api/students', studentRoutes);
app.use((error, req,res,next)=>{
if(error instanceof MulterError){
return res.status(400).send(`Image Error: ${error.message} : ${error.code}`);
}else if(error){
return res.status(500).send(`Something Went Wrong: ${error.message}`);
}
})
export default app;
//app.listen(PORT, ()=>{
// console.log(`Server is Up and runnig at Port: ${PORT} `);
//})