-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
83 lines (69 loc) · 1.8 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const express = require("express");
const bodyParser = require("body-parser");
const helmet = require("helmet");
const compression = require("compression");
const rateLimit = require("express-rate-limit");
const morgan = require("morgan");
const cors = require("cors");
const fs = require("fs");
const path = require("path");
const homedir = require("os").homedir();
require("dotenv").config();
const app = express();
// https://expressjs.com/en/resources/middleware/morgan.html
app.use(morgan("combined"));
//app.use(morgan("common"));
//app.use(morgan("tiny"));
app.use(
morgan("combined", {
stream: fs.createWriteStream(
path.join(homedir, ".config/apidominicans/", "access.log"),
{
flags: "a",
}
),
})
);
app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
extended: true,
})
);
app.use(compression());
app.use(helmet());
const limiter = rateLimit({
windowMs: 1 * 60 * 1000, // 1 minute
max: 45, // 45 requests,
});
app.use(limiter);
app.use(
cors({
origin: [
"https://dominicans.georeligion.org",
"http://localhost:8000",
"http://localhost:3000",
"http://localhost:9000",
"http://localhost:4000",
"http://localhost:8080",
"http://localhost:8081",
"http://192.168.1.10:8080",
],
})
);
// app.use(cors({ origin: "http://localhost:8000" }));
// send API version
app.get("/", (req, res) => {
res.send({ version: process.env.npm_package_version });
});
// getting routes
const works = require("./routes/works");
const houses = require("./routes/houses");
const bishops = require("./routes/bishops");
const resolutions = require("./routes/resolutions");
// applying routes
app.use("/works", works);
app.use("/houses", houses);
app.use("/bishops", bishops);
app.use("/chapters", resolutions);
module.exports = app;