-
Notifications
You must be signed in to change notification settings - Fork 11
/
server.js
50 lines (38 loc) · 1.21 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
46
47
48
49
50
const express = require('express');
const config = require('./config');
const app = require('./app/app');
const apiRouter = require('./app/api');
require('dotenv').config()
if(config.cacheAPI) {
const NodeCache = require('node-cache');
const cache = new NodeCache();
exports.cache = cache;
}
if(config.useMongo) {
const mongoose = require('mongoose');
mongoose.connect(process.env.DB_URL, {useNewUrlParser: true, useUnifiedTopology: true});
const db = mongoose.connection;
// exports.db = db
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
}
if(config.limitAPI) {
const rateLimit = require("express-rate-limit");
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100 // limit each IP to 100 requests per windowMs
});
// apply to all requests
app.use(limiter);
}
if(config.serveDoc) {
app.use(config.docEndpoint, express.static('public/doc'));
}
if(config.serveClientEx) {
app.use(config.clientEndpoint, express.static('public/client'));
}
app.use(config.apiEnpoint, apiRouter);
const port = process.env.PORT || 3000;
// Start the server
app.listen(port, () => {
console.log(`eksisozluk-api running on http://localhost:${port}`);
});