Stackedit/server.js

51 lines
1.1 KiB
JavaScript
Raw Permalink 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
app.set('views', __dirname + '/views');
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 {
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-19 22:59:17 +00:00
// Serve index.html
app.get('/', function (req, res) {
res.render('index.html');
});
app.get('/index.html', function (req, res) {
res.render('index.html');
});
// Serve viewer.html
app.get('/viewer', function (req, res) {
res.render('viewer.html');
});
app.get('/viewer.html', function (req, res) {
res.render('viewer.html');
});
// Error 404
app.use(function(req, res, next){
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);
});