multy-stub/server/routers/epja-2023-2/pen-plotter/index.js
2023-12-07 22:56:11 +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