@@ -6,17 +6,16 @@ import path from 'node:path';
6
6
import jwt from 'jsonwebtoken' ;
7
7
import dayjsModule from 'dayjs' ;
8
8
import { Redis } from 'ioredis' ;
9
+ import { Request } from 'express' ;
9
10
import { logger } from './logger' ;
10
11
import fsp from 'node:fs/promises' ;
11
- import fs from 'node:fs' ;
12
12
import utc from 'dayjs/plugin/utc' ;
13
13
import nodemailer from 'nodemailer' ;
14
14
import { db , redis } from './db/db' ;
15
15
import { Queue , Worker , Job } from 'bullmq' ;
16
16
import timezone from 'dayjs/plugin/timezone' ;
17
17
import { appConfig , emailConfig , oauthConfig , sessionConfig } from './config' ;
18
18
import { GithubUserEmail , GitHubOauthToken , ApiKeyPayload , User } from './types' ;
19
- import { Application , Request , Response , NextFunction } from 'express' ;
20
19
21
20
export function dayjs ( date : string | Date = new Date ( ) ) {
22
21
dayjsModule . extend ( utc ) ;
@@ -285,78 +284,3 @@ export const modifyUserSessionById = async (
285
284
logger . error ( 'No session found for user ID:' , userId ) ;
286
285
return null ;
287
286
} ;
288
-
289
- export function reload ( {
290
- app,
291
- watch,
292
- options = { } ,
293
- } : {
294
- app : Application ;
295
- watch : { path : string ; extensions : string [ ] } [ ] ;
296
- options ?: { pollInterval ?: number ; quiet ?: boolean } ;
297
- } ) : void {
298
- if ( appConfig . env !== 'development' ) return ;
299
-
300
- const pollInterval = options . pollInterval || 50 ;
301
- const quiet = options . quiet || false ;
302
- let changeDetected = false ;
303
- const lastContents = new Map < string , string > ( ) ;
304
-
305
- watch . forEach ( ( { path : dir , extensions } ) => {
306
- const extensionsSet = new Set ( extensions ) ;
307
- fs . watch ( dir , { recursive : true } , ( _ : fs . WatchEventType , filename : string | null ) => {
308
- if ( filename && extensionsSet . has ( filename . slice ( filename . lastIndexOf ( '.' ) ) ) ) {
309
- try {
310
- const fullPath = path . join ( dir , filename ) ;
311
- const content = fs . readFileSync ( fullPath , 'utf8' ) ;
312
-
313
- if ( content !== lastContents . get ( fullPath ) ) {
314
- lastContents . set ( fullPath , content ) ;
315
-
316
- if ( ! quiet ) logger . info ( '[reload] File changed: %s' , filename ) ;
317
- changeDetected = true ;
318
- }
319
- } catch {
320
- if ( ! quiet ) logger . debug ( '[reload] Error reading file: %s' , filename ) ;
321
- }
322
- }
323
- } ) ;
324
- } ) ;
325
-
326
- app . get ( '/wait-for-reload' , ( req : Request , res : Response ) => {
327
- const timer = setInterval ( ( ) => {
328
- if ( changeDetected ) {
329
- changeDetected = false ;
330
- clearInterval ( timer ) ;
331
- res . send ( ) ;
332
- }
333
- } , pollInterval ) ;
334
-
335
- req . on ( 'close' , ( ) => clearInterval ( timer ) ) ;
336
- } ) ;
337
-
338
- const clientScript = `
339
- <script>
340
- (async function poll() {
341
- try {
342
- await fetch('/wait-for-reload');
343
- location.reload();
344
- } catch {
345
- location.reload();
346
- }
347
- })();
348
- </script>\n\t` ;
349
-
350
- app . use ( ( req : Request , res : Response , next : NextFunction ) => {
351
- const originalSend = res . send . bind ( res ) ;
352
-
353
- res . send = function ( body : any ) : Response {
354
- if ( typeof body === 'string' && body . includes ( '</head>' ) ) {
355
- body = body . replace ( '</head>' , clientScript + '</head>' ) ;
356
- }
357
- return originalSend ( body ) ;
358
- } ;
359
-
360
- next ( ) ;
361
- } ) ;
362
- }
0 commit comments