-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (53 loc) · 1.62 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const express=require("express")
const morgan=require("morgan")
const AuthRoute = require('./routes/auth')
const PostRoute = require('./routes/post')
const UserRoute = require('./routes/user')
const AdminRoute = require('./routes/admin')
const AddPostRoute=require('./routes/addPost')
const cors = require('cors')
require('./helpers/init_mongodb')
const createError=require("http-errors")
require('dotenv').config();
var bodyParser = require('body-parser');
const User = require("./models/user")
const app=express();
app.use(cors())
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(morgan('dev'))
app.use("/uploads", express.static(__dirname + '/uploads'));
app.use("/getImg", express.static(__dirname + '/uploads'));
app.get('/', async(req,res,next)=>{
res.send("Hello")
})
app.get('/', async(req,res,next)=>{
res.send("Hello")
})
app.get('/update', async(req,res,next)=>{
const now= new Date().toLocaleString("en-Us", {timeZone: 'Asia/Kolkata'});
const data= await User.updateMany({$set:{dailyDonationCoin:10,coinLastUpdate:now}});
if(data)res.send(200)
else res.send(400)
})
app.use('/auth',AuthRoute)
app.use('/post',PostRoute)
app.use('/addPost/',AddPostRoute)
app.use('/user',UserRoute)
app.use('/adminAll',AdminRoute)
app.use(async (req, res, next) => {
next(createError.NotFound())
})
app.use((err, req, res, next) => {
res.status(err.status || 500)
res.send({
error: {
status: err.status || 500,
message: err.message,
},
})
})
const port=process.env.port || 3000;
app.listen(port,()=>{
console.log(`Server running on port ${port}`)
})