crunch-node/routes-preview.js
2016-01-23 16:24:06 -05:00

146 lines
5.7 KiB
JavaScript

var config = require('./config.js').config;
module.exports = function (app) {
// Routes for previewing sent versions of the built items.
app.get('/blog/*',
require('connect-ensure-login').ensureLoggedIn(),
function(req, res, next) {
if (req.params[0] != '') {
var path = __dirname + '/' + config.genDir + '/blog/' + req.params[0];
console.log('Trying to serve: ' + path);
fs.exists(path, function(exists) {
if (exists) {
console.log(path + ' exists serving...');
res.sendFile(path);
}
else {
console.log(path + ' does not exist...');
if (path.slice(-1) != '/') path += '/';
path += 'index.html'
console.log('Trying to serve: ' + path);
fs.exists(path, function(exists) {
if (exists) {
console.log(path + ' exists serving...');
res.sendFile(path);
}
});
}
});
}
}
);
app.get('/photos/*',
require('connect-ensure-login').ensureLoggedIn(),
function(req, res, next) {
if (req.params[0] != '') {
var path = __dirname + '/' + config.genDir + '/photos/' + req.params[0];
console.log('Trying to serve: ' + path);
fs.exists(path, function(exists) {
if (exists) {
console.log(path + ' exists serving...');
res.sendFile(path);
}
else {
console.log(path + ' does not exist...');
if (path.slice(-1) != '/') path += '/';
path += 'index.html'
console.log('Trying to serve: ' + path);
fs.exists(path, function(exists) {
if (exists) {
console.log(path + ' exists serving...');
res.sendFile(path);
}
});
}
});
}
}
);
app.get('/galleries/*',
require('connect-ensure-login').ensureLoggedIn(),
function(req, res, next) {
if (req.params[0] != '') {
var path = __dirname + '/' + config.genDir + '/galleries/' + req.params[0];
console.log('Trying to serve: ' + path);
fs.exists(path, function(exists) {
if (exists) {
console.log(path + ' exists serving...');
res.sendFile(path);
}
else {
console.log(path + ' does not exist...');
if (path.slice(-1) != '/') path += '/';
path += 'index.html'
console.log('Trying to serve: ' + path);
fs.exists(path, function(exists) {
if (exists) {
console.log(path + ' exists serving...');
res.sendFile(path);
}
});
}
});
}
}
);
app.get('/static/*',
require('connect-ensure-login').ensureLoggedIn(),
function(req, res, next) {
if (req.params[0] != '') {
var path = __dirname + '/' + config.genDir + '/static/' + req.params[0];
console.log('Trying to serve: ' + path);
fs.exists(path, function(exists) {
if (exists) {
console.log(path + ' exists serving...');
res.sendFile(path);
}
else {
console.log(path + ' does not exist...');
if (path.slice(-1) != '/') path += '/';
path += 'index.html'
console.log('Trying to serve: ' + path);
fs.exists(path, function(exists) {
if (exists) {
console.log(path + ' exists serving...');
res.sendFile(path);
}
});
}
});
}
}
);
app.get('/'+config.uploadDir+'/*',
require('connect-ensure-login').ensureLoggedIn(),
function(req, res, next) {
if (req.params[0] != '') {
var path = __dirname + '/'+ config.uploadDir + '/'+ req.params[0];
console.log('Trying to serve: ' + path);
fs.exists(path, function(exists) {
if (exists) {
console.log(path + ' exists serving...');
res.sendFile(path);
}
else {
console.log(path + ' does not exist...');
if (path.slice(-1) != '/') path += '/';
path += 'index.html'
console.log('Trying to serve: ' + path);
fs.exists(path, function(exists) {
if (exists) {
console.log(path + ' exists serving...');
res.sendFile(path);
}
});
}
});
}
}
);
}