ref: backend
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user