<commit_before>const path = require('path');
const Cookies = require("cookies");

const { Shot } = require("./servershot");
const { checkLogin, registerLogin } = require("./users");
const dbschema = require("./dbschema");
const express = require("express");
const bodyParser = require('body-parser');
const morgan = require("morgan");
const linker = require("./linker");

const contentType = "Content-type";

dbschema.createTables();
dbschema.createKeygrip();

const app = express();

app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json({limit: '100mb'}));

app.use("/static", express.static(path.join(__dirname, "static"), {
  index: false
}));

app.use(morgan("dev"));

app.use(function (req, res, next) {
  let cookies = new Cookies(req, res, dbschema.getKeygrip());
  req.userId = cookies.get("user", {signed: true});
  // FIXME: should detect https:
  req.backend = "http://" + req.headers.host;
  next();
});

app.use(function (req, res, next) {
  req.staticLink = linker.staticLink.bind(null, req);
  next();
});

app.use(function (err, req, res, next) {
  console.error("Error:", err);
  console.error(err.stack);
  errorResponse(res, "General error:", err);
});

app.post("/api/register", function (req, res) {
  let vars = req.params;
  // FIXME: need to hash secret
  let canUpdate = vars.userId === req.userId;<commit_msg>Fix #429, get protocol from x-forwarded-proto<commit_after>const path = require('path');
const Cookies = require("cookies");

const { Shot } = require("./servershot");
const { checkLogin, registerLogin } = require("./users");
const dbschema = require("./dbschema");
const express = require("express");
const bodyParser = require('body-parser');
const morgan = require("morgan");
const linker = require("./linker");

const contentType = "Content-type";

dbschema.createTables();
dbschema.createKeygrip();

const app = express();

app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json({limit: '100mb'}));

app.use("/static", express.static(path.join(__dirname, "static"), {
  index: false
}));

app.use(morgan("dev"));

app.use(function (req, res, next) {
  let cookies = new Cookies(req, res, dbschema.getKeygrip());
  req.userId = cookies.get("user", {signed: true});
  let proto = req.headers["x-forwarded-proto"] || "http";
  req.backend = proto + "://" + req.headers.host;
  next();
});

app.use(function (req, res, next) {
  req.staticLink = linker.staticLink.bind(null, req);
  next();
});

app.use(function (err, req, res, next) {
  console.error("Error:", err);
  console.error(err.stack);
  errorResponse(res, "General error:", err);
});

app.post("/api/register", function (req, res) {
  let vars = req.params;
  // FIXME: need to hash secret
  let canUpdate = vars.userId === req.userId;
{'fraction_non_alphanumeric': 0.19603603603603603, 'fraction_numerical': 0.003243243243243243, 'mean_word_length': 5.034782608695652, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, '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': '3669380', 'n_tokens_mistral': 923, 'n_tokens_neox': 908, 'n_words': 212}