-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (36 loc) · 1.22 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
require('dotenv').config();
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const rateLimit = require('express-rate-limit');
const booksRoute = require('./routes/books');
const authRoute = require('./routes/auth');
const usersRoute = require('./routes/users');
const app = express();
const port = process.env.PORT || 3000;
const limiter = rateLimit({
windowMs: 10 * 60 * 1000,
max: 10,
message: 'You requested too much! PLEASE STOP!',
standardHeaders: true,
legacyHeaders: false,
});
app.use(limiter);
app.use(cors());
app.use(express.json());
const mongoDBUri = process.env.MONGODB_URI;
mongoose.connect(mongoDBUri, {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => console.log('Successfully connected to MangoDB!'))
.catch(err => console.error('MongoDB connection error:', err));
app.use('/api/auth', authRoute);
app.use('/api/books', booksRoute);
app.use('/api/users', usersRoute);
app.get('/', (req, res) => {
res.send('Welcome to LibrisAPI. If you visit for the first time, you should want to read the documentation at <a>https://docs.librisapi.necoti.dev</a>');
});
app.listen(port, () => {
console.log(`Server running on the ${port} port`);
});