{"size": 1358, "ext": "js", "max_stars_repo_path": "server.js", "max_stars_repo_name": "reyemtm/spatial-sqlite-api", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server.js", "max_issues_repo_name": "reyemtm/spatial-sqlite-api", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server.js", "max_forks_repo_name": "reyemtm/spatial-sqlite-api", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 19.6811594203, "max_line_length": 66, "alphanum_fraction": 0.5662739323}
require("dotenv").config();
const fastify = require("fastify")({
  logger: {
    level: "warn",
  },
});

const genKeys = (string) => {
  if (!string) return
  const array = (string.includes(",")) ? string.split(",") : null;
  if (!array) return
  const keys = [];
  for (let i = 0; i < array.length; i++) {
    let hasKey = false
    keys.forEach(k => {
      if (k.file === array[i]) {
        k.keys.push(array[i+1])
        hasKey = true
      }
    });
    if (!hasKey) {
      keys.push({
        file: array[i],
        keys: [array[i+1]]
      })
    }
    i++
  }
  return keys
}

const options = {
  keys: genKeys(process.env.KEYS),
  cookieName: "_ssql"
}

fastify.register(require('fastify-cors'), { 
  // put your options here
})

fastify.register(require("fastify-rate-limit"), {
  max: 100,
  timeWindow: "1 minute",
});
// fastify.register(require("fastify-swagger"), {
//   exposeRoute: true,
//   routePrefix: "/docs",
//   swagger: {
//     info: { title: "fastify-api" },
//   },
// });

// fastify.register(require("./routes/items"));
fastify.register(require("./routes/Home"));
fastify.register(require("./routes/SpatialRoute"), options);

const PORT = process.env.PORT || 5000;

const start = async () => {
  try {
    await fastify.listen(PORT);
  } catch (error) {
    fastify.log.error(error);
    process.exit(1);
  }
};

start();
