<commit_before>import express from "express";
import bodyParser from "body-parser";
import fs from "fs";
import tmp from "tmp";
import { exec } from "child_process";

const app = express();

app.use(express.static("pkg"));
app.use(bodyParser.text({ type: 'text/plain' }));

app.get("/", function (req, res) {
  res.sendFile(__dirname + "/pkg/demo/quill/index.html");
});

const RAKSHA_BINARY = '/usr/src/app/raksha/bazel-bin/src/backends/policy_engine/souffle/check_policy_compliance';
const RAKSHA_POLICY = '/usr/src/app/raksha/src/backends/policy_engine/souffle/testdata/arcsjs_policy_rules.txt';

app.post("/raksha", async function (req, res) {
    const data = req.body;
    tmp.file(function (err, path, fd, cleanup) {
      if (err) throw err;
      fs.appendFile(path, new Buffer(data), function (err) {
        if (err) {
          res.send("2");
        }
      });
      exec(`${RAKSHA_BINARY} --ir ${path} --sql_policy_rules=${RAKSHA_POLICY} --policy_engine=`,
          async (err, stdout, stderr) => {
        if (err) { console.error(err); res.send("1"); } else {
          res.send("0");
        }
        console.log(stdout);
      });<commit_msg>Workaround __dirname not in esm<commit_after>import express from "express";
import bodyParser from "body-parser";
import fs from "fs";
import tmp from "tmp";
import { exec } from "child_process";
import { fileURLToPath } from 'url';
import { dirname } from 'path';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const app = express();

app.use(express.static("pkg"));
app.use(bodyParser.text({ type: 'text/plain' }));

app.get("/", function (req, res) {
  res.sendFile(__dirname + "/pkg/demo/quill/index.html");
});

const RAKSHA_BINARY = '/usr/src/app/raksha/bazel-bin/src/backends/policy_engine/souffle/check_policy_compliance';
const RAKSHA_POLICY = '/usr/src/app/raksha/src/backends/policy_engine/souffle/testdata/arcsjs_policy_rules.txt';

app.post("/raksha", async function (req, res) {
    const data = req.body;
    tmp.file(function (err, path, fd, cleanup) {
      if (err) throw err;
      fs.appendFile(path, new Buffer(data), function (err) {
        if (err) {
          res.send("2");
        }
      });
      exec(`${RAKSHA_BINARY} --ir ${path} --sql_policy_rules=${RAKSHA_POLICY} --policy_engine=`,
          async (err, stdout, stderr) => {
        if (err) { console.error(err); res.send("1"); } else {
          res.send("0");
        }
        console.log(stdout);
      });
{'fraction_non_alphanumeric': 0.17172523961661343, 'fraction_numerical': 0.0023961661341853034, 'mean_word_length': 3.4257950530035335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5839377', 'n_tokens_mistral': 875, 'n_tokens_neox': 870, 'n_words': 178}