-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
83 lines (68 loc) · 2.02 KB
/
app.js
File metadata and controls
83 lines (68 loc) · 2.02 KB
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 path = require("path");
const { limiter } = require("./modules/rateLimiter");
require("dotenv").config();
const app = express();
app.use(express.json());
app.use(limiter);
app.set("json spaces", 2);
app.set('trust proxy', 1)
// Set up the templating engine to build HTML for the front end.
app.set("views", path.join(__dirname, "./views"));
app.set("view engine", "ejs");
// Have express server static content( images, CSS, browser JS) from the public
app.use(express.static(path.join(__dirname, "./public")));
//route logic
app.use("/api/v0", require("./routes/api_routes"));
//render logic
app.use("/", require("./routes/render"));
// Hold list of functions to run when the server is ready
app.onListen = [
function () {
console.log("Express is ready");
},
];
/*
potential features
1) accept text / excel file and look up ip addresses
2) accept text / excel file and look up domain names
3) cache
4) db support for optimization
*/
/*
Note to self regarding API services in used.
1) maxmind geo ip locater
2) Whatismybrowser
3) domain lookup
*/
// Catch 404 and forward to error handler. If none of the above routes are
// used, this is what will be called.
app.use(function (req, res, next) {
var err = new Error("Not Found");
err.message = "Page not found";
err.status = 404;
res.json({ error: err.message });
next(err);
});
app.use(function (err, req, res, next) {
if (![404, 401, 422].includes(err.status || res.status)) {
console.error(err.message);
console.error(err.stack);
console.error("=========================================");
}
res.status(err.status || 500);
});
//setinterval to load mmdb files from redist
setInterval(() => {
import('geolite2-redist')
.then(geolite => geolite.downloadDbs())
.catch(error => {
console.error('Error downloading MMDB files:', error.message);
console.error(error.stack);
});
}, 43200000);
//listen to port
// app.listen(process.env.port, () => {
// console.log("Server is running on port 80");
// });
module.exports = app;