create custom view for redirect and custom view for not found

This commit is contained in:
Bilal Catic
2019-10-10 00:49:48 +02:00
parent 20a93b7fdc
commit 40fb1e6ad7
4 changed files with 65 additions and 4 deletions

View File

@@ -11,6 +11,30 @@ const redirect = async (req, res) => {
}
};
module.exports = {
redirect
const getRedirect = async (req, res) => {
const id = req.params.id || null;
let error = false;
let redirectUrl = undefined;
if (!id) {
error = true;
} else {
const realEstate = await getRealEstateById(id);
if (!realEstate) {
error = true;
} else {
redirectUrl = realEstate.url;
}
}
if (error) {
const title = "";
res.render("notFound", { title });
} else {
const title = "Preusmjeravanje";
res.render("redirect", { title, redirectUrl });
}
};
module.exports = {
getRedirect
};

View File

@@ -18,7 +18,7 @@ const { getGoAgain } = require("../controllers/goAgain");
const { getLocation, postLocation } = require("../controllers/location");
const { getUnsubscribe } = require("../controllers/unsubscribe");
const { getRealEstates } = require("../controllers/realEstates");
const { redirect } = require("../controllers/redirect");
const { getRedirect } = require("../controllers/redirect");
const router = express.Router();
@@ -50,6 +50,6 @@ router.get("/ponovo", getGoAgain);
router.get("/nekretnine/:searchRequestId", getRealEstates);
router.get("/redirect/:id", redirect);
router.get("/redirect/:id", getRedirect);
module.exports = router;

9
app/views/notFound.ejs Normal file
View File

@@ -0,0 +1,9 @@
<!--suppress HtmlUnknownAnchorTarget -->
<% include partials/navBar %>
<div class="row center">
<h4>Ups...stranica ne postoji</h4>
</div>
<div class="row center">
<h5><a href="/">Nova pretraga</a></h5>
</div>

28
app/views/redirect.ejs Normal file
View File

@@ -0,0 +1,28 @@
<!--suppress HtmlUnknownAnchorTarget -->
<% include partials/navBar %>
<div class="center">
<div class="preloader-wrapper big active center">
<div class="spinner-layer spinner-green-only">
<div class="circle-clipper left">
<div class="circle"></div>
</div><div class="gap-patch">
<div class="circle"></div>
</div><div class="circle-clipper right">
<div class="circle"></div>
</div>
</div>
</div>
</div>
<br>
<div class="center">
<h6>
<a href="<%= redirectUrl %>" rel="noreferrer" id="realEstateUrl">Kliknite ovdje ako Vas web preglednik ne preusmjeri automatski</a>
</h6>
</div>
<script>
window.onload = () => {
document.getElementById('realEstateUrl').click();
}
</script>