I have a cron job that is supposed to send an email with a link to the system every month.
However, this is a whiteboxed application that will be run on different domains.
I am trying to dynamically generate the link in the cron job. I have done this before by accessing the req object in a GET or POST request but I know there is no way to access these objects in a cron job. I am trying to find a way to generate the link in the Cron Job with out hardcoding the protocol and domain in the link that is sent out.
See example below:
const express = require("express");
const cron = require('node-cron');
const app = express();
cron.schedule("0 8 1 * *", async () =>
{
let protocol = `https`; // Functionality to detect if protocol is http or https
let domainAndPort = `www.test.com:7443`; // Functionality to detect doamin and port that app is listening on.
let link = `${protocol}://${domainAndPort}/`;
//Send Email with Link using nodemailer
/*
In a GET or POST request I normally generate the link like this
let link = `${req.protocol}://${req.headers.host}/`;
*/
}
app.get("/", function(req, res)
{
res.send("HELLO");
});
app.listen(7443, function()
{
console.log(`Listening on port 7443`);
});