import http from 'node:http'; const originalCreateServer = http.createServer.bind(http); const originalWriteHead = http.ServerResponse.prototype.writeHead; const originalEnd = http.ServerResponse.prototype.end; const layoutPatch = ``; http.createServer = function (...args) { const listenerIndex = args.findIndex(value => typeof value === 'function'); if (listenerIndex >= 0) { const listener = args[listenerIndex]; args[listenerIndex] = (req, res) => { const pathname = String(req.url || '').split('?')[0]; if (pathname === '/favicon.ico') { res.writeHead(204, { 'cache-control': 'public, max-age=86400' }); return res.end(); } return listener(req, res); }; } return originalCreateServer(...args); }; http.ServerResponse.prototype.writeHead = function (statusCode, ...args) { if (statusCode === 400 && String(this.req?.url || '').startsWith('/callback')) { this.setHeader('Location', '/login'); statusCode = 302; } return originalWriteHead.call(this, statusCode, ...args); }; http.ServerResponse.prototype.end = function (chunk, encoding, callback) { if (typeof chunk === 'string') { chunk = chunk.replaceAll('Arrowstack Tasks', 'i love you tasks'); if (chunk.includes('')) { chunk = chunk.replace('', `${layoutPatch}`); } } return originalEnd.call(this, chunk, encoding, callback); }; await import('./server.js');