File tree 4 files changed +48
-8
lines changed
4 files changed +48
-8
lines changed Original file line number Diff line number Diff line change @@ -39,4 +39,4 @@ ENV NODE_ENV=production
39
39
ENV RSS_WATCHER_DATA_DIR=/app/data
40
40
41
41
# Start the application
42
- CMD ["npm " , "start " ]
42
+ CMD ["node " , "dist/server/index.js " ]
Original file line number Diff line number Diff line change @@ -151,12 +151,12 @@ export class FeedMonitor {
151
151
private async sendNotification ( item : FeedItem ) {
152
152
const config = this . configManager . getConfig ( ) ;
153
153
const ntfyUrl = `${ config . ntfyServerAddress } /${ config . ntfyTopic } ` ;
154
- // console.log(`Sending notification for ${ item.title}` );
154
+ const sanitizedTitle = item . title . replace ( / [ ^ \x20 - \x7E ] / g , '' ) ;
155
155
156
156
try {
157
157
// Sanitize the title by removing any characters
158
158
// that aren't in the ASCII printable range (0x20 to 0x7E)
159
- const sanitizedTitle = item . title . replace ( / [ ^ \x20 - \x7E ] / g , '' ) ;
159
+ console . log ( `Sending notification for ${ sanitizedTitle } ` ) ;
160
160
await fetch ( ntfyUrl , {
161
161
method : 'POST' ,
162
162
body : item . description ,
@@ -166,7 +166,7 @@ export class FeedMonitor {
166
166
}
167
167
} ) ;
168
168
} catch ( error ) {
169
- console . error ( `Error sending notification for ${ item . title } :` , error ) ;
169
+ console . error ( `Error sending notification for ${ sanitizedTitle } :` , error ) ;
170
170
}
171
171
}
172
172
Original file line number Diff line number Diff line change 1
1
import './bootstrap.js' ;
2
2
import { Server } from './server.js' ;
3
3
4
+ let server : Server ;
5
+
4
6
async function startApp ( ) {
5
- const server = new Server ( ) ;
7
+ server = new Server ( ) ;
6
8
await server . start ( 3000 ) ;
7
9
}
8
10
11
+ async function shutdown ( signal : string ) {
12
+ console . log ( `\nReceived ${ signal } , starting graceful shutdown...` ) ;
13
+ if ( server ) {
14
+ await server . stop ( ) ;
15
+ console . log ( 'Server stopped successfully' ) ;
16
+ }
17
+ process . exit ( 0 ) ;
18
+ }
19
+
20
+ // Handle shutdown signals
21
+ process . on ( 'SIGTERM' , ( ) => shutdown ( 'SIGTERM' ) ) ;
22
+ process . on ( 'SIGINT' , ( ) => shutdown ( 'SIGINT' ) ) ;
23
+
9
24
startApp ( ) . catch ( console . error ) ;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ export class Server {
12
12
private app : express . Application ;
13
13
private configManager : ConfigManager ;
14
14
private feedMonitor : FeedMonitor ;
15
+ private server ?: ReturnType < typeof express . application . listen > ;
15
16
16
17
constructor ( ) {
17
18
this . app = express ( ) ;
@@ -122,12 +123,36 @@ export class Server {
122
123
123
124
public async start ( port : number = 3000 ) {
124
125
await this . setupVite ( ) ;
125
- this . app . listen ( port , ( ) => {
126
- console . log ( `Server running on port ${ port } ` ) ;
126
+ this . server = this . app . listen ( port , ( ) => {
127
+ console . log ( `
128
+ ╔═══════════════════════════════════════════╗
129
+ ║ RSS Watcher ║
130
+ ╚═══════════════════════════════════════════╝
131
+ 🚀 Server is running on port ${ port }
132
+ 📡 Mode: ${ process . env . NODE_ENV || 'production' }
133
+
134
+ Monitoring your feeds! 📰
135
+ ` ) ;
127
136
} ) ;
128
137
}
129
138
130
- public stop ( ) {
139
+ public async stop ( ) {
140
+ console . log ( 'Stopping feed monitor...' ) ;
131
141
this . feedMonitor . stop ( ) ;
142
+
143
+ if ( this . server ) {
144
+ console . log ( 'Closing HTTP server...' ) ;
145
+ return new Promise < void > ( ( resolve , reject ) => {
146
+ this . server ! . close ( ( err ) => {
147
+ if ( err ) {
148
+ console . error ( 'Error while closing HTTP server:' , err ) ;
149
+ reject ( err ) ;
150
+ } else {
151
+ console . log ( 'HTTP server closed successfully' ) ;
152
+ resolve ( ) ;
153
+ }
154
+ } ) ;
155
+ } ) ;
156
+ }
132
157
}
133
158
}
You can’t perform that action at this time.
0 commit comments