35 lines
863 B
JavaScript
35 lines
863 B
JavaScript
|
const dotenv = require('dotenv');
|
||
|
const express = require('express');
|
||
|
const helmet = require("helmet");
|
||
|
const rateLimit = require("express-rate-limit");
|
||
|
const config = require("./config/configuration");
|
||
|
const logger = require("./services/logging");
|
||
|
|
||
|
dotenv.config();
|
||
|
|
||
|
const poll = require("./services/poll");
|
||
|
setInterval(poll, 5000);
|
||
|
|
||
|
const PORT = process.env.PORT || config.web.port || 9111;
|
||
|
|
||
|
const app = express();
|
||
|
app.use(express.json());
|
||
|
app.use("/", require("./routes/home"));
|
||
|
app.use("/api", require("./routes/api"));
|
||
|
|
||
|
const limiter = rateLimit({
|
||
|
legacyHeaders: true,
|
||
|
standardHeaders: true,
|
||
|
windowMs: 15 * 60 * 1000,
|
||
|
limit: 50,
|
||
|
max: 2,
|
||
|
message: "Too many requests; please try again later.",
|
||
|
keyGenerator: (req) => req.ip,
|
||
|
});
|
||
|
|
||
|
app.use(helmet());
|
||
|
app.use(limiter);
|
||
|
|
||
|
app.listen(PORT, () => {
|
||
|
logger.info("Listening to port " + PORT + ".");
|
||
|
});
|