Skip to content

Commit

Permalink
Rely more on the config variable than imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Airbus-A330 committed Aug 14, 2022
1 parent 5894fee commit 924eb4f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ require("dotenv").config();
app.use(bodyParser.json());

const creationRL = new RL({
limit: require("./Config/config.js").ratelimits.creation.limit,
reset: require("./Config/config.js").ratelimits.creation.reset,
limit: config.ratelimits.creation.limit,
reset: config.ratelimits.creation.reset,
});
const viewingRL = new RL({
limit: require("./Config/config.js").ratelimits.viewing.limit,
reset: require("./Config/config.js").ratelimits.viewing.reset,
limit: config.ratelimits.viewing.limit,
reset: config.ratelimits.viewing.reset,
});

(async () => {
Expand Down Expand Up @@ -172,7 +172,7 @@ app.post("/urls", async (req, res) => {
}
}

let id = await require("./Functions/idGen.js")(require("./Config/config.js").id.length);
let id = await require("./Functions/idGen.js")(config.id.length);

const url = new URLs({
_id: id,
Expand All @@ -189,7 +189,7 @@ app.post("/urls", async (req, res) => {
status: 200,
message: "The shortened URL path has been successfully created!",
code: id,
retain: require("./Config/config.js").retain
retain: config.retain
});

await console.log(
Expand All @@ -200,11 +200,11 @@ app.post("/urls", async (req, res) => {
creationRL.increment(req.headers['cf-connecting-ip'] ?? req.headers['x-forwarded-for']);
});

if (require("./Config/config.js").retain > 0) {
if (config.retain > 0) {
setTimeout(async () => {
let urls = await URLs.find({}).lean().exec();
for (const url of urls) {
if ((url.created_at + require("./Config/config.js").retain) < Date.now()) {
if ((url.created_at + config.retain) < Date.now()) {
await URLs.findOneAndDelete({
_id: url._id
}).lean().exec();
Expand Down

0 comments on commit 924eb4f

Please sign in to comment.