Stackedit/app/index.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-08-13 21:06:14 +00:00
var express = require('express');
var app = express();
// Configure ejs engine
app.set('views', __dirname + '/../public');
app.engine('html', require('ejs').renderFile);
// Force HTTPS on stackedit.io
app.all('*', function(req, res, next) {
if (req.headers.host == 'stackedit.io' && 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-18 23:30:45 +00:00
/\.(eot|ttf|woff)$/.test(req.url) && res.header('Access-Control-Allow-Origin', '*');
next();
2014-08-13 21:06:14 +00:00
});
// Use gzip compression
app.use(express.compress());
// Serve static resources
app.use(express.static(__dirname + '/../public'));
2014-08-25 08:18:14 +00:00
// Serve editor.html in /viewer
app.get('/editor', function (req, res) {
res.render('editor.html');
});
2014-08-13 21:06:14 +00:00
// Serve viewer.html in /viewer
app.get('/viewer', function (req, res) {
res.render('viewer.html');
});
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-08-13 21:06:14 +00:00
// Error 404
app.use(function(req, res, next) {
res.status(404);
res.render('error_404.html');
});
module.exports = app;