2014-08-13 21:06:14 +00:00
|
|
|
var express = require('express');
|
|
|
|
var app = express();
|
2014-08-27 23:04:27 +00:00
|
|
|
var compression = require('compression');
|
|
|
|
var serveStatic = require('serve-static');
|
2014-08-13 21:06:14 +00:00
|
|
|
|
|
|
|
// Configure ejs engine
|
2014-08-27 23:04:27 +00:00
|
|
|
app.set('views', __dirname + '/../views');
|
2014-08-13 21:06:14 +00:00
|
|
|
app.engine('html', require('ejs').renderFile);
|
|
|
|
|
|
|
|
// Force HTTPS on stackedit.io
|
|
|
|
app.all('*', function(req, res, next) {
|
2014-12-17 00:31:18 +00:00
|
|
|
if (req.headers.host == 'stackedit.io' && !req.secure && req.headers['x-forwarded-proto'] != 'https') {
|
2014-08-18 23:30:45 +00:00
|
|
|
return res.redirect('https://stackedit.io' + req.url);
|
2014-08-13 21:06:14 +00:00
|
|
|
}
|
2014-08-31 19:51:13 +00:00
|
|
|
/\.(eot|ttf|woff|svg)$/.test(req.url) && res.header('Access-Control-Allow-Origin', '*');
|
2014-08-18 23:30:45 +00:00
|
|
|
next();
|
2014-08-13 21:06:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Use gzip compression
|
2014-08-27 23:04:27 +00:00
|
|
|
app.use(compression());
|
2014-08-13 21:06:14 +00:00
|
|
|
|
2014-08-27 23:04:27 +00:00
|
|
|
app.post('/pdfExport', require('./pdf').export);
|
|
|
|
app.post('/sshPublish', require('./ssh').publish);
|
|
|
|
app.post('/picasaImportImg', require('./picasa').importImg);
|
|
|
|
app.get('/downloadImport', require('./download').importPublic);
|
|
|
|
|
2014-09-06 00:11:06 +00:00
|
|
|
// Serve static resources
|
|
|
|
app.use(serveStatic(__dirname + '/../public'));
|
|
|
|
|
2014-08-27 23:04:27 +00:00
|
|
|
app.use(function(req, res, next) {
|
|
|
|
res.renderDebug = function(page) {
|
|
|
|
return res.render(page, {
|
2014-09-06 00:11:06 +00:00
|
|
|
cache: !req.query.hasOwnProperty('debug')
|
2014-08-27 23:04:27 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Serve landing.html in /
|
|
|
|
app.get('/', function(req, res) {
|
|
|
|
res.renderDebug('landing.html');
|
|
|
|
});
|
2014-08-13 21:06:14 +00:00
|
|
|
|
2014-08-25 08:18:14 +00:00
|
|
|
// Serve editor.html in /viewer
|
2014-08-27 23:04:27 +00:00
|
|
|
app.get('/editor', function(req, res) {
|
|
|
|
res.renderDebug('editor.html');
|
2014-08-25 08:18:14 +00:00
|
|
|
});
|
|
|
|
|
2014-08-13 21:06:14 +00:00
|
|
|
// Serve viewer.html in /viewer
|
2014-08-27 23:04:27 +00:00
|
|
|
app.get('/viewer', function(req, res) {
|
|
|
|
res.renderDebug('viewer.html');
|
2014-08-13 21:06:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Error 404
|
2014-08-27 23:04:27 +00:00
|
|
|
app.use(function(req, res) {
|
2014-08-13 21:06:14 +00:00
|
|
|
res.status(404);
|
|
|
|
res.render('error_404.html');
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = app;
|