-
Notifications
You must be signed in to change notification settings - Fork 5
/
comb.js
50 lines (43 loc) · 1.41 KB
/
comb.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport();
function reportError(subject, text) {
transporter.sendMail({
from: '[email protected]',
to: '[email protected]',
subject: subject + ' ' + Date.now(),
text: text,
html: '<pre>' + text + '</pre>'
});
}
function reportUnacceptedReferer(referer) {
reportError('Unaccepted referer', referer);
}
function reportParsingError(css, error) {
reportError('Parsing error', error.stack + '\n\n\n' + css);
}
module.exports = function(req, res){
var Comb = require('csscomb'),
comb = new Comb('csscomb'),
input = req.body.input,
output;
// GATE:
var acceptedReferers = [
'http://localhost:4444/online',
'http://csscomb.herokuapp.com/online',
'https://csscomb.herokuapp.com/online',
'http://csscomb.com/online',
'http://csscomb.com/online/'
];
if (acceptedReferers.indexOf(req.headers.referer) < 0)
reportUnacceptedReferer(req.headers.referer);
// Comb it, baby:
try {
output = comb.processString(input);
} catch (e) {
output = 'Something went wrong.\nPlease make sure that you\'re trying ' +
'to comb a valid CSS (not Sass or Less).\nOr maybe you forgot ' +
'a closing brace?\n\nHere is an error message:\n\n' + e.message;
reportParsingError(input, e);
}
res.send(output);
}