aboutsummaryrefslogtreecommitdiffstats
path: root/prettier/server.js
blob: d75204665a076410969820dafabe7e1dc2850639 (plain) (blame)
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
#!/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);