const express = require('express')
const router = express.Router()
const fs = require("fs");
const path = require("path");
const { BASE_PATH } = require("./paths");

router.use("/profiles", express.static(path.join(BASE_PATH, "/profiles")));
router.use("/static", express.static(path.join(BASE_PATH, "/static")));

router.use('/api', require('./routes/api').default)

// Add the required directories
router.use((req, res, next) => {
  const directories = ["/static", "/profiles"];
  directories.forEach((dir) => {
    if (!fs.existsSync(BASE_PATH + dir)) {
      fs.mkdirSync(BASE_PATH + dir);
    }
  });
  next();
});


router.get('/info', (req, res) => {
  res.send('Pen-Plotter backend')
})

module.exports = router
