forked from mrded/pandoc-as-a-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
33 lines (27 loc) · 887 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var express = require('express'),
helpers = require('./helpers'),
pdc = require('pdc');
this.server = express();
this.server.set('views', './views');
this.server.set('view engine', 'ejs');
this.server.use(express.static('public'));
this.server.get('/', function(req, res) {
res.render('index');
});
this.server.post('/:format', function(req, res) {
var contentType = req.get('Content-Type');
if (contentType) {
var from = contentType.split("/")[1];
var to = req.params.format;
helpers.getBody(req, function(body) {
pdc(body, from, to, function(err, result) {
if (err) res.sendStatus(400)
else res.append('Content-Type', 'text/' + to).send(result);
});
});
} else res.sendStatus(400)
});
exports.listen = function(port) {
this.server.listen(port);
console.log("Express server listening on port %d", port);
};