ref: backend

This commit is contained in:
Andrey
2023-12-07 22:56:11 +03:00
parent 07d23f6bec
commit 2d414c86b4
100 changed files with 459 additions and 95 deletions
+11 -18
View File
@@ -2,31 +2,24 @@ 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)
const BASE_PATH = __dirname;
const STATIC_PATH = `${BASE_PATH}/static`;
// Serve static files
router.use(express.static(path.join(__dirname, './assets/')))
// Add the required directories
router.use((req, res, next) => {
const directories = ['/static', '/profiles']
const directories = ["/static", "/profiles"];
directories.forEach((dir) => {
if (!fs.existsSync(BASE_PATH + dir)) {
fs.mkdirSync(BASE_PATH + dir)
fs.mkdirSync(BASE_PATH + dir);
}
})
next()
})
// Serve Static generated SVGs
router.get('/static/:name', async (req, res, next) => {
const fileName = req.params.name
const filePath = `${STATIC_PATH}/${fileName}`
});
next();
});
const file = await fs.readFileSync(filePath)
res.setHeader('Content-Type', 'image/svg+xml')
res.send(file)
})
router.use('/api', require('./routes/api').default)
router.get('/info', (req, res) => {
res.send('Pen-Plotter backend')