Stackedit/server.js

41 lines
1.0 KiB
JavaScript
Raw Normal View History

2013-09-27 23:41:15 +00:00
var express = require('express');
var app = express();
2013-10-07 01:17:55 +00:00
2013-10-19 22:59:17 +00:00
// Configure ejs engine
2013-10-24 21:03:24 +00:00
app.set('views', __dirname + '/public');
2013-10-19 22:59:17 +00:00
app.engine('html', require('ejs').renderFile);
2013-10-07 01:17:55 +00:00
// Force HTTPS on stackedit.io
2013-10-07 01:11:56 +00:00
app.all('*', function(req, res, next) {
if (req.headers.host == 'stackedit.io' && req.headers['x-forwarded-proto'] != 'https') {
res.redirect('https://stackedit.io' + req.url);
}
else {
2014-06-09 16:37:04 +00:00
/\.(eot|ttf|woff)$/.test(req.url) && res.header('Access-Control-Allow-Origin', '*');
2013-10-07 01:11:56 +00:00
next();
}
});
2013-10-07 01:17:55 +00:00
// Use gzip compression
2013-09-27 23:41:15 +00:00
app.use(express.compress());
2013-10-07 01:17:55 +00:00
// Serve static resources
2013-10-06 20:26:11 +00:00
app.use(express.static(__dirname + '/public'));
2013-10-07 01:17:55 +00:00
2013-10-24 21:03:24 +00:00
// Serve viewer.html in /viewer
2013-10-19 22:59:17 +00:00
app.get('/viewer', function (req, res) {
res.render('viewer.html');
});
// Error 404
2013-10-24 21:03:24 +00:00
app.use(function(req, res, next) {
2013-10-19 22:59:17 +00:00
res.status(404);
res.render('error_404.html');
});
2013-10-07 01:17:55 +00:00
// Listen on port 3000
2013-10-09 23:51:35 +00:00
var port = process.env.PORT || 3000;
app.listen(port, null, function() {
console.log('Server started: http://localhost:' + port);
});