Spaces:
Runtime error

Dhurgh commited on
Commit
6835a10
·
1 Parent(s): 546580c

Add required Hugging Face metadata

Browse files
Files changed (1) hide show
  1. README.md +12 -488
README.md CHANGED
@@ -1,488 +1,12 @@
1
- # Ultimate Chat App
2
-
3
- A modern, feature-rich real-time chat application built with Socket.IO, Express, and vanilla JavaScript.
4
-
5
- ## Features
6
-
7
- ### Core Functionality
8
- - **Real-time Messaging** - Instant message delivery using WebSocket technology
9
- - **Online Users List** - See who's currently active in the chat
10
- - **Typing Indicators** - Know when someone is typing a message
11
- - **Message History** - New users can see the last 50 messages
12
- - **Persistent Sessions** - Messages are saved during the session
13
-
14
- ### User Experience
15
- - **Modern UI/UX** - Beautiful gradient design with smooth animations
16
- - **Dark/Light Theme** - Toggle between themes, preference saved locally
17
- - **Emoji Support** - Built-in emoji picker with popular emojis
18
- - **Sound Notifications** - Audio alerts for new messages
19
- - **Smart Timestamps** - Dynamic time display (just now, X mins ago, etc.)
20
- - **Mobile Responsive** - Works perfectly on all device sizes
21
- - **User Avatars** - Auto-generated avatars with first letter of username
22
-
23
- ### UI Features
24
- - Smooth fade-in animations for messages
25
- - Auto-scroll to latest messages
26
- - Custom scrollbar design
27
- - Clean, organized message bubbles
28
- - Distinct styling for own vs others' messages
29
- - System notifications for user joins/leaves
30
- - Professional header with action buttons
31
-
32
- ## Getting Started
33
-
34
- ### Prerequisites
35
- - Node.js (v14 or higher)
36
- - npm or yarn
37
- - PostgreSQL (local) or managed PostgreSQL (Render/Railway/Neon/Supabase)
38
-
39
- ### Installation
40
-
41
- 1. Navigate to the project directory:
42
- ```bash
43
- cd message
44
- ```
45
-
46
- 2. Install dependencies:
47
- ```bash
48
- npm install
49
- ```
50
-
51
- 3. Start the server:
52
- ```bash
53
- npm start
54
- ```
55
-
56
- Or for development with auto-restart:
57
- ```bash
58
- npm run dev
59
- ```
60
-
61
- 4. Open your browser and navigate to:
62
- ```
63
- http://localhost:3000
64
- ```
65
-
66
- ## Reproducible Setup (Ubuntu Server / Raspberry Pi)
67
-
68
- This section is intended for assignment reproducibility requirements.
69
-
70
- ### 1) Install system packages
71
-
72
- ```bash
73
- sudo apt update
74
- sudo apt install -y curl git ca-certificates postgresql postgresql-contrib
75
- ```
76
-
77
- ### 2) Install Node.js LTS
78
-
79
- ```bash
80
- curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
81
- sudo apt install -y nodejs
82
- node -v
83
- npm -v
84
- ```
85
-
86
- ### 3) Clone repository
87
-
88
- ```bash
89
- git clone https://github.com/dhurghamCreation/FireTech-Messager-Server.git
90
- cd FireTech-Messager-Server
91
- ```
92
-
93
- ### 4) Create PostgreSQL database/user
94
-
95
- ```bash
96
- sudo -u postgres psql -c "CREATE USER firetech WITH PASSWORD 'change_this_password';"
97
- sudo -u postgres psql -c "CREATE DATABASE firetech_db OWNER firetech;"
98
- ```
99
-
100
- ### 5) Configure environment variables
101
-
102
- Create `.env`:
103
-
104
- ```env
105
- PORT=3000
106
- HOST=0.0.0.0
107
- NODE_ENV=production
108
- DATABASE_URL=postgres://firetech:change_this_password@localhost:5432/firetech_db
109
- JWT_SECRET=replace_with_long_random_secret
110
- CORS_ORIGIN=*
111
- ```
112
-
113
- ### 6) Install dependencies and run
114
-
115
- ```bash
116
- npm install
117
- npm start
118
- ```
119
-
120
- ### 7) Verify service is running
121
-
122
- ```bash
123
- curl http://localhost:3000/api/version
124
- ```
125
-
126
- Expected output includes the app version as JSON.
127
-
128
- ### 8) (Optional) Run with PM2 for persistence
129
-
130
- ```bash
131
- sudo npm install -g pm2
132
- pm2 start server.js --name firetech-chat
133
- pm2 save
134
- pm2 startup
135
- ```
136
-
137
- ### Quick HTTPS Setup for LAN Access (Windows)
138
-
139
- Run this **one command** in PowerShell to set up HTTPS with automatic certificate generation and firewall configuration:
140
-
141
- ```powershell
142
- .\setup-https.ps1
143
- ```
144
-
145
- Or using npm:
146
-
147
- ```powershell
148
- npm run https
149
- ```
150
-
151
- This will:
152
- - Auto-detect your LAN IP
153
- - Generate trusted HTTPS certificate
154
- - Configure Windows Firewall
155
- - Start the app on `https://localhost:3001`
156
- - Enable LAN access from mobile devices
157
-
158
- ## Enable HTTPS
159
-
160
- The server now supports HTTPS automatically when you provide certificate paths.
161
-
162
- ### 1) Create or obtain certificates
163
-
164
- - **Development (self-signed):** use OpenSSL or `mkcert`
165
- - **Production:** use a trusted cert (for example Let's Encrypt)
166
-
167
- ### 2) Set environment variables
168
-
169
- Windows PowerShell:
170
-
171
- ```powershell
172
- $env:SSL_KEY_PATH="C:\path\to\key.pem"
173
- $env:SSL_CERT_PATH="C:\path\to\cert.pem"
174
- $env:PORT="3000"
175
- npm start
176
- ```
177
-
178
- Without `SSL_KEY_PATH` and `SSL_CERT_PATH`, the app falls back to HTTP.
179
-
180
- ### Windows-only quick setup (no OpenSSL/mkcert required)
181
-
182
- You can create a local `.pfx` certificate with built-in PowerShell commands:
183
-
184
- ```powershell
185
- cd C:\Users\dell\Downloads\message
186
- New-Item -ItemType Directory -Force certs | Out-Null
187
- $cert = New-SelfSignedCertificate -DnsName "localhost" -CertStoreLocation "cert:\CurrentUser\My"
188
- $pwd = ConvertTo-SecureString -String "123456" -Force -AsPlainText
189
- Export-PfxCertificate -Cert $cert -FilePath ".\certs\localhost.pfx" -Password $pwd
190
-
191
- $env:SSL_PFX_PATH="C:\Users\dell\Downloads\message\certs\localhost.pfx"
192
- $env:SSL_PFX_PASSPHRASE="123456"
193
- $env:PORT="3001"
194
- npm start
195
- ```
196
-
197
- Open:
198
-
199
- ```
200
- https://localhost:3001
201
- ```
202
-
203
- If browser warns about certificate trust, continue for local development.
204
-
205
- ### 3) Open HTTPS URL
206
-
207
- ```
208
- https://localhost:3000
209
- ```
210
-
211
- For self-signed certificates, your browser will show a warning unless the cert is trusted locally.
212
-
213
- ## Allow connections beyond localhost
214
-
215
- The server now listens on `0.0.0.0` by default, so devices on your network can connect.
216
-
217
- ### LAN access (same Wi-Fi/network)
218
-
219
- **Step 1:** Find your PC's LAN IP address:
220
-
221
- ```powershell
222
- (Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.InterfaceAlias -notlike "*Loopback*" -and $_.IPAddress -notlike "169.254.*"}).IPAddress
223
- ```
224
-
225
- Example output: `192.168.1.25`
226
-
227
- **Step 2:** Allow firewall for the app port:
228
-
229
- ```powershell
230
- New-NetFirewallRule -DisplayName "Chat App HTTPS" -Direction Inbound -LocalPort 3001 -Protocol TCP -Action Allow
231
- ```
232
-
233
- **Step 3:** Generate cert for both localhost and LAN IP:
234
-
235
- ```powershell
236
- cd C:\Users\dell\Downloads\message
237
- taskkill /F /IM node.exe
238
-
239
-
240
- $cert = New-SelfSignedCertificate `
241
- -Subject "CN=localhost" `
242
- -CertStoreLocation "Cert:\CurrentUser\My" `
243
- -KeyAlgorithm RSA -KeyLength 2048 `
244
- -HashAlgorithm SHA256 `
245
- -NotAfter (Get-Date).AddYears(2) `
246
- -TextExtension @("2.5.29.17={text}DNS=localhost&IPAddress=192.168.56.1")
247
-
248
- $pwd = ConvertTo-SecureString "123456" -AsPlainText -Force
249
- Export-PfxCertificate -Cert $cert -FilePath ".\certs\lan-localhost.pfx" -Password $pwd
250
- Export-Certificate -Cert $cert -FilePath ".\certs\lan-localhost.cer" -Force
251
- Import-Certificate -FilePath ".\certs\lan-localhost.cer" -CertStoreLocation "Cert:\CurrentUser\Root"
252
-
253
- $env:SSL_PFX_PATH = (Resolve-Path ".\certs\lan-localhost.pfx").Path
254
- $env:SSL_PFX_PASSPHRASE = "123456"
255
- $env:PORT = "3001"
256
- npm start
257
- ```
258
-
259
- **Step 4:** Open from any device on your network:
260
- - On same PC: `https://localhost:3001`
261
- - On mobile/other PC: `https://192.168.56.1:3001` (use your actual IP)
262
-
263
- **Note:** Mobile devices will show cert warning (self-signed). Click "Advanced" → "Proceed" for local testing.
264
-
265
- ### Internet access (different networks) - RECOMMENDED: Use Cloud Deployment
266
-
267
- For users on different internet connections (cellular, other Wi-Fi), **deploy to a free cloud service** instead of exposing your home network:
268
-
269
- | Option | Difficulty | Cost | HTTPS | Best For |
270
- |--------|-----------|------|-------|----------|
271
- | Railway | Easy | Free tier | Auto | Quick deployment, beginners |
272
- | Render | Easy | Free tier | Auto | Node + WebSocket apps with simple setup |
273
- | Self-host (DuckDNS+Caddy) | Hard | Free | Auto | Learning, full control |
274
-
275
- #### Option 1: Deploy to Railway (Easiest - Free HTTPS + Domain)
276
-
277
- 1. Create account at https://railway.app
278
- 2. Install Railway CLI:
279
- ```powershell
280
- npm install -g @railway/cli
281
- ```
282
- 3. Deploy:
283
- ```powershell
284
- cd C:\Users\dell\Downloads\message
285
- railway login
286
- railway init
287
- railway up
288
- ```
289
- 4. Get your public URL:
290
- ```powershell
291
- railway domain
292
- ```
293
- 5. Share the URL (automatic HTTPS included!)
294
-
295
- #### Option 2: Deploy to Render (recommended)
296
-
297
- This app is already compatible with Render because it uses a dynamic port (`process.env.PORT`) and Socket.IO over a Node web service.
298
-
299
- 1. Push your latest code to GitHub.
300
- 2. Go to https://render.com and sign in with GitHub.
301
- 3. Click **New +** → **Web Service**.
302
- 4. Choose **Build and deploy from a Git repository** and select this repo.
303
- 5. Configure service settings:
304
- - **Runtime:** `Node`
305
- - **Build Command:** `npm install`
306
- - **Start Command:** `npm start`
307
- - **Plan:** `Free`
308
- - **Region:** nearest to your users
309
- 6. Add environment variables from your local `.env` file (never commit secrets):
310
- - `DATABASE_URL`
311
- - `JWT_SECRET`
312
- - `CORS_ORIGIN` (set to your frontend URL or `*` for quick testing)
313
- - Optional TURN variables for WebRTC: `TURN_URLS`, `TURN_USERNAME`, `TURN_CREDENTIAL`
314
- 7. Click **Create Web Service** and wait for build logs to finish.
315
- 8. Open your live URL: `https://<your-service>.onrender.com`
316
- 9. Validate health endpoint in browser:
317
- - `https://<your-service>.onrender.com/api/version`
318
- 10. Test real-time chat from 2 browser tabs/devices.
319
-
320
- Notes for Render Free tier:
321
- - Free services sleep after inactivity; first wake-up request can take around 30-60 seconds.
322
- - This app uses PostgreSQL via `DATABASE_URL`, so chat/account data is persisted in DB, not only in memory.
323
- - Do not set `PORT` manually on Render; Render injects it automatically.
324
-
325
- #### Option 3: Self-host with proper domain (Advanced)
326
-
327
- For advanced users who want to host from home with a real domain:
328
-
329
- **Requirements:**
330
- - Static public IP or dynamic DNS (DuckDNS)
331
- - Router port forwarding access
332
- - Reverse proxy (Caddy recommended for auto-HTTPS)
333
-
334
- **Steps:**
335
- 1. Get free domain: https://www.duckdns.org
336
- 2. Install Caddy on Windows: https://caddyserver.com/docs/install
337
- 3. Configure router port forward: `80` and `443` → your PC
338
- 4. Edit `Caddyfile` (included in project) with your domain
339
- 5. Run your Node app: `npm start`
340
- 6. Run Caddy in another terminal: `caddy run`
341
- 7. Caddy automatically gets Let's Encrypt certificate!
342
-
343
- **Security Note:** Self-hosting exposes your home network. Use strong passwords, keep software updated, and consider a VPS instead.
344
-
345
- ## How to Use
346
-
347
- 1. **Join the Chat**
348
- - Enter your desired username when prompted
349
- - Click "Join Chat" or press Enter
350
-
351
- 2. **Send Messages**
352
- - Type your message in the input field
353
- - Click the send button or press Enter
354
- - Your messages appear on the right (blue)
355
- - Others' messages appear on the left (gray)
356
-
357
- 3. **Use Emojis**
358
- - Click the emoji button (smiley face icon)
359
- - Select from popular emojis
360
- - Emojis are added to your message
361
-
362
- 4. **Switch Themes**
363
- - Click "Toggle Theme" in the sidebar
364
- - Your preference is saved automatically
365
-
366
- 5. **View Online Users**
367
- - Check the sidebar to see all active users
368
- - Your name is highlighted
369
- - Green dot indicates online status
370
-
371
- 6. **Clear Chat**
372
- - Click the trash icon in the header
373
- - Confirm to clear all messages (local only)
374
-
375
- ## Project Structure
376
-
377
- ```
378
- message/
379
- ├── index.html # Main HTML with embedded CSS
380
- ├── client.js # Client-side JavaScript & Socket.IO logic
381
- ├── server.js # Express server & Socket.IO backend
382
- ├── package.json # Project dependencies
383
- ├── README.md # This file
384
- ├── setup-https.ps1 # Quick HTTPS setup script for Windows
385
- ├── railway.json # Railway deployment config
386
- ├── render.yaml # Render deployment config
387
- ├── Caddyfile # Caddy reverse proxy config (for self-hosting)
388
- ├── .gitignore # Git ignore rules
389
- └── certs/ # Local HTTPS certificates (auto-generated)
390
- ```
391
-
392
- ## Technologies Used
393
-
394
- - **Backend**: Node.js, Express.js, Socket.IO
395
- - **Frontend**: HTML5, CSS3, Vanilla JavaScript
396
- - **Icons**: Font Awesome 6
397
- - **Real-time Communication**: Socket.IO (WebSocket)
398
-
399
- ## Design Highlights
400
-
401
- ### Color Scheme
402
- - Primary: Purple gradient (#667eea → #764ba2)
403
- - Light theme: Clean whites and grays
404
- - Dark theme: Deep blacks with purple accents
405
-
406
- ### Animations
407
- - Fade-in animations for new messages
408
- - Typing indicator with bouncing dots
409
- - Smooth hover effects on buttons
410
- - Slide-in modal animations
411
-
412
- ## Configuration
413
-
414
- ### Environment variables
415
-
416
- Set these before starting the app:
417
-
418
- ```javascript
419
- const PORT = process.env.PORT || 3000;
420
- const HOST = process.env.HOST || '0.0.0.0';
421
- ```
422
-
423
- - `PORT`: server port (default `3000`)
424
- - `HOST`: bind address (default `0.0.0.0`)
425
- - `SSL_KEY_PATH`: absolute path to TLS private key (`.pem`)
426
- - `SSL_CERT_PATH`: absolute path to TLS certificate (`.pem`)
427
- - `SSL_PFX_PATH`: absolute path to TLS certificate bundle (`.pfx`)
428
- - `SSL_PFX_PASSPHRASE`: passphrase for `.pfx` (if set)
429
- - `CORS_ORIGIN`: optional comma-separated allowed origins for Socket.IO (default `*`)
430
-
431
- ### Adjust Message History
432
- Edit `server.js`:
433
- ```javascript
434
- const MAX_HISTORY = 50;
435
- ```
436
-
437
- ## Features in Detail
438
-
439
- ### Typing Indicators
440
- When you start typing, other users see a real-time "typing..." indicator. It automatically disappears after 1 second of inactivity.
441
-
442
- ### Message History
443
- New users joining the chat can see the last 50 messages, allowing them to catch up on the conversation.
444
-
445
- ### Smart Timestamps
446
- - "Just now" for messages < 1 minute old
447
- - "X mins ago" for messages < 1 hour old
448
- - Time (HH:MM) for messages today
449
- - Date + time for older messages
450
-
451
- ### User Management
452
- - Automatic user tracking by socket connection
453
- - Real-time updates when users join/leave
454
- - Broadcast notifications to all connected clients
455
-
456
- ## Future Enhancements
457
-
458
- Potential features to add:
459
- - File/image sharing
460
- - Private messaging
461
- - Chat rooms
462
- - Message search
463
- - Database integration for persistent history
464
- - User authentication
465
- - Read receipts
466
- - Message reactions
467
- - Video/voice calls
468
-
469
- ## License
470
-
471
- This project is open source and available for personal and commercial use.
472
-
473
- ## Developer
474
-
475
- Created by Dhurgham Alsaadi using modern web technologies.
476
-
477
- ## GenAI Usage Disclosure
478
-
479
- GenAI assistance was used for selected coding tasks. In-code disclosure comments are included in:
480
- - `server.js`
481
- - `client.js`
482
- - `index.html`
483
-
484
- Prompt summaries used are documented in those file comments as required.
485
-
486
- ---
487
-
488
- **Enjoy chatting!**
 
1
+ ---
2
+ title: FireTech Message Server
3
+ emoji: ??
4
+ colorFrom: blue
5
+ colorTo: indigo
6
+ sdk: docker
7
+ app_port: 7860
8
+ pinned: false
9
+ ---
10
+
11
+ # FireTech Messager Server
12
+ Node.js Express backend migrated to Hugging Face Spaces.