Blame Raw
Cohee · 51ad27fb · · 19 lines (596 B)
1 contributor
1import path from 'node:path';
2import 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 */
8export 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
19export default userCssMiddleware;