Moved to more partials

This commit is contained in:
Kasper Rynning-Tønnesen
2017-10-17 13:56:46 +02:00
parent 0f6e9f8161
commit 3fbfb6c12f
21 changed files with 564 additions and 655 deletions

View File

@@ -12,38 +12,7 @@ router.use(function(req, res, next) {
});
router.route('/:channel_name').get(function(req, res, next){
try{
var url = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'] : req.headers.host.split(":")[0];
var subdomain = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'].split(".") : req.headers.host.split(":")[0].split(".");
if(url != "zoff.me" && url != "remote.zoff.me" && url != "fb.zoff.me" && url != "remote.localhost" && url != "localhost") {
res.redirect("https://zoff.me");
return;
}
if(subdomain[0] == "remote") {
var data = {
year: 2017,
javascript_file: "remote.min.js"
}
res.render('layouts/remote', data);
} else if(subdomain.length >= 2 && subdomain[0] == "www") {
res.redirect("https://zoff.me");
} else {
if(req.params.channel_name == "_embed") {
res.sendFile(path.join(pathThumbnails, '/public/assets/html/embed.html'));
} else if(req.params.channel_name == "o_callback") {
res.sendFile(path.join(pathThumbnails, '/public/assets/html/callback.html'));
} else {
var data = {
list_name: capitalizeFirstLetter(req.params.channel_name),
year: 2017,
javascript_file: "main.min.js"
}
res.render('layouts/channel', data);
}
}
} catch(e) {
res.redirect("https://zoff.me");
}
channel(req, res, next);
});
router.route('/api/frontpages').get(function(req, res) {
@@ -120,46 +89,6 @@ router.route('/api/imageblob').post(function(req, res) {
});
});
/*
*
* TODO:
*
* Add custom userplaylists, only visible for those with that specific cookie
*
*
router.route('/:user_name/:channel_name').get(function(req, res, next){
var protocol = req.protocol;
var subdomain = req.headers['x-forwarded-host'].split(".");
if((subdomain[0] != 'localhost' && !(subdomain.length >= 2 && subdomain[1] == 'localhost')) && protocol != "https") {
res.redirect("https://zoff.me");
return;
}
if(subdomain[0] == "remote") {
var data = {
year: 2017,
javascript_file: "remote.min.js"
}
res.render('layouts/remote', data);
} else if(subdomain.length >= 2 && subdomain[0] == "www") {
res.redirect("https://zoff.me");
} else {
if(req.params.channel_name == "_embed") {
res.sendFile(path.join(__dirname, '/public/assets/html/embed.html'));
} else if(req.params.channel_name == "o_callback") {
res.sendFile(path.join(__dirname, '/public/assets/html/callback.html'));
} else {
var data = {
list_name: capitalizeFirstLetter(req.params.channel_name),
year: 2017,
javascript_file: "main.min.js"
}
res.render('layouts/channel', data);
}
}
});
*/
router.route('/api/mail').post(function(req, res) {
let transporter = nodemailer.createTransport(mailconfig);
@@ -191,35 +120,15 @@ router.route('/api/mail').post(function(req, res) {
});
router.route('/').get(function(req, res, next){
try{
var url = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'] : req.headers.host.split(":")[0];
var subdomain = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'].split(".") : req.headers.host.split(":")[0].split(".");
if(url != "zoff.me" && url != "remote.zoff.me" && url != "fb.zoff.me" && url != "remote.localhost" && url != "localhost") {
res.redirect("https://zoff.me");
return;
}
if(subdomain[0] == "remote") {
var data = {
year: 2017,
javascript_file: "remote.min.js"
}
res.render('layouts/remote', data);
} else if(subdomain[0] == "www") {
res.redirect("https://zoff.me");
} else {
var data = {
year: 2017,
javascript_file: "main.min.js"
}
res.render('layouts/frontpage', data);
}
} catch(e) {
//console.log(e);
//res.redirect("https://zoff.me");
}
root(req, res, next);
});
router.route('/').post(function(req, res, next){
root(req, res, next);
});
function root(req, res, next) {
try{
var url = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'] : req.headers.host.split(":")[0];
var subdomain = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'].split(".") : req.headers.host.split(":")[0].split(".");
@@ -238,7 +147,7 @@ router.route('/').post(function(req, res, next){
} else {
var data = {
year: 2017,
javascript_file: "main.min.js"
javascript_file: "main.min.js",
}
res.render('layouts/frontpage', data);
}
@@ -246,9 +155,9 @@ router.route('/').post(function(req, res, next){
//console.log(e);
//res.redirect("https://zoff.me");
}
});
}
router.route('/:channel_name').post(function(req, res, next){
function channel(req, res, next) {
try{
var url = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'] : req.headers.host.split(":")[0];
var subdomain = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'].split(".") : req.headers.host.split(":")[0].split(".");
@@ -281,9 +190,7 @@ router.route('/:channel_name').post(function(req, res, next){
} catch(e) {
res.redirect("https://zoff.me");
}
});
}
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);