aboutsummaryrefslogtreecommitdiffstats
path: root/prettier/server.js
diff options
context:
space:
mode:
Diffstat (limited to 'prettier/server.js')
-rwxr-xr-xprettier/server.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/prettier/server.js b/prettier/server.js
new file mode 100755
index 0000000..d752046
--- /dev/null
+++ b/prettier/server.js
@@ -0,0 +1,25 @@
+#!/usr/bin/env node
+"use strict";
+
+const express = require("express");
+const prettier = require("prettier");
+
+const app = express();
+app.use(express.json());
+
+// app.use((req, res, next) => {
+// res.append("Access-Control-Allow-Origin", ["*"]);
+// res.append("Access-Control-Allow-Methods", "POST", "OPTIONS");
+// res.append("Access-Control-Allow-Headers", "Content-Type");
+// next();
+// });
+
+app.post("/api/v1/format", async function (req, res) {
+ const formattedText = await prettier.format(req.body["content"], {
+ parser: "babel",
+ });
+ res.set("Content-Type", "application/json");
+ res.json({ formattedText: formattedText });
+});
+
+app.listen(9001);