-
-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathbs-config.mementomods.js
More file actions
62 lines (59 loc) 路 1.78 KB
/
Copy pathbs-config.mementomods.js
File metadata and controls
62 lines (59 loc) 路 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Browsersync configuration for proxying mementomori.social
const { createProxyMiddleware, responseInterceptor } = require('http-proxy-middleware');
const variant = process.env.VARIANT;
const cssFile = variant || 'mastodon-bird-ui';
const theme = variant || 'mastodon-bird-ui-dark';
const proxy = createProxyMiddleware({
target: 'https://mementomori.social',
changeOrigin: true,
secure: true,
selfHandleResponse: true,
on: {
proxyRes: responseInterceptor(async (responseBuffer, proxyRes, req, res) => {
// Remove CSP header so Browsersync's injected script can run
res.removeHeader('content-security-policy');
// Only modify HTML responses
const contentType = proxyRes.headers['content-type'] || '';
if (contentType.includes('text/html')) {
let html = responseBuffer.toString('utf8');
// Override data-user-theme attribute in HTML tag
html = html.replace(/data-user-theme="[^"]*"/, `data-user-theme="${theme}"`);
// Inject CSS before </head>
const injection = `
<link rel="stylesheet" href="/mastodon-bird-ui/${cssFile}.css">
`;
html = html.replace(/<\/head>/i, injection + '</head>');
return html;
}
// Return unchanged for non-HTML (JSON, etc.)
return responseBuffer;
}),
},
});
module.exports = {
server: {
baseDir: '.',
middleware: [proxy],
},
serveStatic: [
{
route: '/mastodon-bird-ui',
dir: 'dist',
},
],
port: 3999,
files: ['dist/*.css'],
open: false,
notify: true,
logLevel: 'info',
logPrefix: 'Bird UI (mementomods)',
reloadDelay: 0,
reloadDebounce: 100,
injectChanges: true,
watchEvents: ['change', 'add'],
watchOptions: {
usePolling: true,
interval: 500,
},
ignore: ['node_modules', '.git', '*.map'],
};