-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
38 lines (31 loc) · 981 Bytes
/
index.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
var g2js = require('gradle-to-js/lib/parser');
var express = require('express')
var bodyParser = require('body-parser')
var app = express()
var port = process.env.PORT || 5000;
app.use(bodyParser.text());
app.disable('x-powered-by');
app.use(function(req, res, next) {
res.set('Access-Control-Allow-Origin', '*');
next();
});
app.post("/parse/", bodyParser.text({type: '*/*'}), function(req,res){
g2js.parseText(req.body).then(function(representation) {
res.end(JSON.stringify(representation))
}).catch (function(err) {
console.error('ERROR: ', err);
console.error('STACK: ', err.stack)
res.status(500).send({error: 'Something went wrong.'});
});
});
app.get("/", function(req, res) {
res.send("OK");
});
app.use(function(err, req, res, next) {
console.error('ERR:', err);
console.error('STACK:', err.stack);
res.status(500).send({error: 'Something went wrong.'});
});
app.listen(port, function() {
console.log('Listening on', port);
});