Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
Access domain and protocol in Node Cron Job

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`);
});
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda