| 1 | import path from 'node:path'; |
| 2 | import fs from 'node:fs'; |
| 3 | |
| 4 | /** |
| 5 | * Provides an Express middleware function that serves a user-defined CSS file from the data directory if it exists. |
| 6 | * @type {import('express').Handler} |
| 7 | */ |
| 8 | export function userCssMiddleware(req, res, next) { |
| 9 | if (req.method === 'GET' && req.path === '/css/user.css') { |
| 10 | const userCssPath = path.resolve(path.join(globalThis.DATA_ROOT, '_css', 'user.css')); |
| 11 | if (fs.existsSync(userCssPath)) { |
| 12 | res.sendFile(userCssPath); |
| 13 | return; |
| 14 | } |
| 15 | } |
| 16 | next(); |
| 17 | } |
| 18 | |
| 19 | export default userCssMiddleware; |