-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
48 lines (41 loc) · 969 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const express = require('express');
const app = express();
const sass = require('node-sass');
const bodyParser = require('body-parser');
app.use((req, res, next) => {
res.header({
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-type',
});
next();
});
app.use((req, res, next) => {
req.headers['content-type'] = 'application/json';
next();
});
// parse application/json
app.use(bodyParser.json());
app.get('/', (req, res) => res.json(true));
app.post('/', (req, res) => {
const source = req.body.source;
sass.render(
{
data: source,
},
(error, result) => {
if (error) {
return res.json({
error,
source,
});
}
return res.json({
source,
result: result.css.toString(),
});
}
);
});
const listener = app.listen(process.env.PORT, () => {
console.log('Your app is listening on port ' + listener.address().port);
});