forked from akashrchandran/Rayso-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (56 loc) · 1.57 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const express = require("express");
const RaySo = require("rayso-api");
const app = express();
app.use(express.json());
app.get("/", (req, res) => {
res.end("Hello World!");
});
app.get("/api", (req, res) => {
if (!req.query.code) {
res.status(400);
res.json({"error": "code query parameter is missing."});
return;
}
const raySo = new RaySo({
title: req.query.title,
theme: req.query.theme,
padding: req.query.padding,
language: req.query.language,
background: req.query.background,
darkMode: req.query.darkMode
});
raySo
.cook(`${req.query.code}`)
.then((response) => {
res.end(response, "binary");
})
.catch((err) => {
console.error(err);
});
});
app.post("/api", (req, res) => {
if (!req.body.code) {
res.status(400);
res.json({"error": "Body cannot be empty or missing code parameter."})
return;
}
const raySo = new RaySo({
title: req.body.title,
theme: req.body.theme,
padding: req.body.padding,
language: req.body.language,
background: req.body.background,
darkMode: req.body.darkMode
});
raySo
.cook(`${req.body.code}`)
.then((response) => {
res.end(response, "binary");
})
.catch((err) => {
console.error(err);
});
});
app.listen(process.env.PORT || 3000, () => {
console.log(`app listening`);
});