-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
42 lines (36 loc) · 1.26 KB
/
app.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
require('dotenv').config()
const express = require('express')
const mongoose = require('mongoose')
const userRoutes = require('./routes/user.js')
const hashRoutes = require('./routes/datahash.js')
const commentRoutes = require('./routes/comment.js')
const rateLimit = require("express-rate-limit")
const MongoStore = require('rate-limit-mongo')
const morgan = require('morgan')
const cors = require('cors')
const app = express()
mongoose.connect(process.env.DB, {useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false, useCreateIndex: true}, error => {
if(error){
console.log('not connected\n', error)
} else {
console.log('connected')
}
});
// app.set('trust proxy')
app.use(cors())
app.use(express.urlencoded({extended: true}))
app.use(express.json())
app.use(rateLimit({windowMs: 60000, max: 120, message: 'Too many connections from this client', store: new MongoStore({uri: process.env.DB})}))
app.use(morgan('tiny'))
app.get('/', (req, res) => {
return res.status(200).json('success')
})
app.use('/user', userRoutes)
app.use('/datahash', hashRoutes)
app.use('/comment', commentRoutes)
app.get('*', (req, res) => {
return res.status(400).json('error')
})
app.listen(process.env.PORT, () => {
console.log('listening')
})