change how APP_URL is used, use JS templating string

This commit is contained in:
Bilal Catic
2019-09-05 14:24:29 +02:00
parent f311404968
commit 1d29f6c8ac
4 changed files with 50 additions and 50 deletions

9
app/config/appConfig.js Normal file
View File

@@ -0,0 +1,9 @@
const APP_PORT = process.env.APP_PORT || 5000;
const APP_BASE_URL = process.env.APP_BASE_URL || "http://localhost";
const APP_URL = `${APP_BASE_URL}:${APP_PORT}`;
module.exports = {
APP_PORT,
APP_URL
};

View File

@@ -1,3 +1,4 @@
const { APP_URL } = require("../config/appConfig");
const { getRealEstateTypeEnum } = require("./enums");
const { getRegionName, getMunicipalityName } = require("./codes");
const { allRERequestByUiid } = require("./db/dbHelper");
@@ -82,15 +83,15 @@ const getGreetingsEmailHTML = realestateRequest => {
<div>
</div>
<div><strong> Ako želis prestati dobijati obavještenja za ovu pretragu klikni ${
process.env.APP_URL
}/odjava/${realestateRequest.uniqueId} </strong></div>
<div><strong>Ako želiš promijeniti uslove pretrage klikni ${
process.env.APP_URL
}/pregled/${realestateRequest.uniqueId} </strong></div>
<h4> Tvoj,
Javimi tim.
</h4>`;
<div><strong> Ako želis prestati dobijati obavještenja za ovu pretragu klikni ${APP_URL}/odjava/${
realestateRequest.uniqueId
} </strong></div>
<div><strong>Ako želiš promijeniti uslove pretrage klikni ${APP_URL}/pregled/${
realestateRequest.uniqueId
} </strong></div>
<h4> Tvoj,
Javimi tim.
</h4>`;
};
const getGreetingsEmaiTextVersion = realestateRequest => {
@@ -98,40 +99,27 @@ const getGreetingsEmaiTextVersion = realestateRequest => {
realestateRequest.realEstateType
);
const gardenSize = realEstateType.hasGardenSize
? "Kvadratura okućnice od " +
realestateRequest.gardenSizeMin +
" do " +
realestateRequest.gardenSizeMax
? `Kvadratura okućnice od ${realestateRequest.gardenSizeMin} do ${realestateRequest.gardenSizeMax}`
: "";
const text =
"Zdravo, \n Naručio/la si da ti javimo ako se nekretnina pojavi u oglasima \n Ovo je tražena nekretnina: \n , Tip nekretnine: " +
realestateRequest.realEstateType +
"\n Područje" +
getRegionName(realestateRequest.region) +
"\n Mjesto " +
getMunicipalityName(
realestateRequest.region,
realestateRequest.municipality
) +
"\n Kvadratura nekretnine Od " +
realestateRequest.sizeMin +
" do " +
realestateRequest.sizeMaX +
+gardenSize;
"\n Cijena od " +
realestateRequest.priceMin +
" do " +
realestateRequest.priceMax +
"\n Ako želis prestati dobijati obavještenja za ovu pretragu klikni" +
process.env.APP_URL +
"/odjava/" +
realestateRequest.uniqueId +
"\n Ako želiš promijeniti uslove pretrage klikni " +
process.env.APP_URL +
"/odpregled/" +
realestateRequest.uniqueId +
"\n Tvoj,\n Javimi tim";
const text = `Zdravo, \n Naručio/la si da ti javimo ako se nekretnina pojavi u oglasima
\n Ovo je tražena nekretnina: \n , Tip nekretnine: ${
realestateRequest.realEstateType
} \n Područje ${getRegionName(
realestateRequest.region
)} \n Mjesto ${getMunicipalityName(
realestateRequest.region,
realestateRequest.municipality
)}
\n Kvadratura nekretnine Od ${realestateRequest.sizeMin} do ${
realestateRequest.sizeMaX
} ${gardenSize} \n Cijena od ${realestateRequest.priceMin} do ${
realestateRequest.priceMax
} \n Ako želis prestati dobijati obavještenja za ovu pretragu klikni
${APP_URL}/odjava/${
realestateRequest.uniqueId
}\n Ako želiš promijeniti uslove pretrage klikni
${APP_URL}/odpregled/${realestateRequest.uniqueId}\n Tvoj,\n Javimi tim`;
return text;
};
@@ -162,7 +150,7 @@ const sendBulkEmail = async marketAlerts => {
realEstateType: RERequest.realEstateType,
region: RERequest.region,
municipality: RERequest.municipality,
requestUrl: `${process.env.APP_URL}/nekretnine/${RERequest.uniqueId}`
requestUrl: `${APP_URL}/nekretnine/${RERequest.uniqueId}`
};
});
@@ -233,8 +221,7 @@ const sendBulkEmail = async marketAlerts => {
}
};
const redirectUrl = marketAlertId =>
`${process.env.APP_URL}/redirect/${marketAlertId}`;
const redirectUrl = marketAlertId => `${APP_URL}/redirect/${marketAlertId}`;
const toAWSArray = urlArray => {
let arrayString = "";
urlArray.forEach(element => {
@@ -247,11 +234,11 @@ const toAWSArray = urlArray => {
};
const getNotificationEmailHtml = () => {
return `<h2> Zdravo,
return `<h2> Zdravo,
Pronašli smo nekretninu koju ste tražili. </h2>
<h3> Ovo su tražene nekretnine: </h3>
<h3> Ovo su tražene nekretnine: </h3>
<div>
<div>{{#each marketAlertUrl}}<li><a href="{{url}}">{{title}}</a></li><br />{{/each}}<div/>
<div>{{#each marketAlertUrl}}<li><a href="{{url}}">{{title}}</a></li><br />{{/each}}<div/>
<div/>
<div>Kompletan spisak nekretnina možete pegledati ovdije: <a href="{{requestUrl}}">Nekretnine</a> <div>
</div>`;

View File

@@ -5,6 +5,9 @@ DB_PORT=Database port
SEQUELIZE_LOGGING=0- no sequelize logging, 1- log to the console
APP_PORT=Port for the app, defaults to 5000
APP_BASE_URL=base url for the app
AMAZON_ACCES_KEY_ID=(your-key-here)
AMAZON_SECRET_ACCESS_KEY=(your-key-here)
AMAZON_REGION=eu-west-1

View File

@@ -1,4 +1,5 @@
require("dotenv").config();
const { APP_PORT } = require("./app/config/appConfig");
const welcome = require("./app/controllers/welcome").getWelcome;
const {
@@ -50,8 +51,6 @@ const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const port = process.env.PORT || 5000;
app.set("views", path.join(__dirname, "/app/views"));
app.set("view engine", "ejs");
app.use(layout());
@@ -182,7 +181,9 @@ app.get("/redirect/:id", redirect);
app.use("/assets", express.static("./app/public"));
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
app.listen(APP_PORT, () =>
console.log(`Example app listening on port ${APP_PORT}!`)
);
var rule = new schedule.RecurrenceRule();
rule.seccond = 1;