forked from karimomaya/OTCL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·32 lines (26 loc) · 991 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
#!/usr/bin/env node
let express = require('express');
let bodyParser = require('body-parser');
let urlencodedParser = bodyParser.urlencoded({ extended: false });
let app = express();
let port = 3001;
let __OTCompiler = require("./engine/__OTCompiler.js");
app.use(express.static(__dirname));
app.post('/', urlencodedParser, function(req, res){
__OTCompiler().evaluator(b64DecodeUnicode(req.body.otcl))
});
var server = app.listen(port, () => {
var host = server.address().address;
var port = server.address().port;
console.log("OTCL app listening at http://%s:%s", host, port);
});
app.get('/', function (req, res) {
res.sendFile(__dirname + "/" + "index.html");
});
function b64DecodeUnicode(str) {
str= str.replace(" ", "+");
var atob = require('atob');
return decodeURIComponent(atob(str).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}