multy-stub/server/routers/old/epja-2023-2/pen-plotter/index.js
Primakov Alexandr Alexandrovich 4b0d9b4dbc mongoose + tests
2024-10-16 11:06:23 +03:00

29 lines
720 B
JavaScript

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