multy-stub/server/routers/epja-2023-2/pen-plotter/index.js

29 lines
720 B
JavaScript
Raw Normal View History

2023-11-25 11:56:14 +03:00
const express = require('express')
2023-11-25 11:55:44 +03:00
const router = express.Router()
2023-11-25 11:56:14 +03:00
const fs = require("fs");
const path = require("path");
2023-12-07 22:56:11 +03:00
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)
2023-11-25 11:56:14 +03:00
// Add the required directories
router.use((req, res, next) => {
2023-12-07 22:56:11 +03:00
const directories = ["/static", "/profiles"];
2023-11-25 11:56:14 +03:00
directories.forEach((dir) => {
if (!fs.existsSync(BASE_PATH + dir)) {
2023-12-07 22:56:11 +03:00
fs.mkdirSync(BASE_PATH + dir);
2023-11-25 11:56:14 +03:00
}
2023-12-07 22:56:11 +03:00
});
next();
});
2023-11-25 11:56:14 +03:00
2023-11-25 11:55:44 +03:00
router.get('/info', (req, res) => {
2023-11-25 11:56:14 +03:00
res.send('Pen-Plotter backend')
2023-11-25 11:55:44 +03:00
})
module.exports = router