-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
39 lines (34 loc) · 945 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
const express = require("express");
const cors = require("cors");
const lexer = require("jlua/lib/lexer");
const Lexer = lexer.Lexer;
const Source = lexer.Source;
const Parser = require("jlua/lib/parser").Parser;
const YamlVisitor = require("jlua/lib/visitor").YamlVisitor;
const compile = require("jlua/lib/js/compile").default;
const port = 8081;
const app = express();
app.use(cors());
app.use(express.json());
app.post("/ast", (req, res) => {
const src = new Source(req.body.code, "stdin");
const lexer = new Lexer(src);
const parser = new Parser(lexer);
const chk = parser.parseChunk();
const v = new YamlVisitor();
const ast = v.visitChunk(chk);
res.send({
code: 0,
data: ast
});
});
app.post("/js", (req, res) => {
const { code } = compile(req.body.code, "stdin");
res.send({
code: 0,
data: code
});
});
app.listen(port, () =>
console.log(`Compiling service is listening on port ${port}!`)
);