-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
602 lines (505 loc) · 23.4 KB
/
app.js
File metadata and controls
602 lines (505 loc) · 23.4 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const multer = require("multer");
const upload = multer();
const cookieParser = require('cookie-parser');
const session = require('express-session');
const path = require('path');
// const nodemailer = require('nodemailer');
const bcrypt = require('bcryptjs');
const { gmailSend } = require('./gmail');
const { pool } = require('./db');
const passport = require('passport');
require('./passport-setup');
const rateLimit = require('express-rate-limit');
const app = express();
const PORT = process.env.PORT || 3000;
// ---------- Middleware ----------
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, 'public')));
app.set('trust proxy', 1);
app.use(cookieParser());
const SESSION_SECRET =
process.env.SESSION_SECRET ||
(process.env.NODE_ENV !== 'production'
? 'spaceapp_super_secret'
: null);
if (process.env.NODE_ENV === 'production' && !SESSION_SECRET) {
throw new Error("SESSION_SECRET is required");
}
// remember to check prod env ensure SESSION_SECRET is there. if not generate locally and then push: node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
app.use(session({
secret: SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie: {
secure: process.env.NODE_ENV === 'production',
httpOnly: true,
sameSite: 'lax'
}
}));
app.use(passport.initialize());
app.use(passport.session());
// ---------- Rate Limiter (DDos and DoS attacks best-effort prevent) ----------
const authLimiter = rateLimit({
windowMs: 5 * 60 * 1000, // 5 minutes in ms
max: 10, // max 10 attempts per window
message: 'Too many attempts, please wait a few minutes.'
});
const otpLimiter = rateLimit({
windowMs: 5 * 60 * 1000,
max: 5,
message: 'Too many OTP requests, please wait a few minutes.'
});
const verifyLimiter = rateLimit({
windowMs: 5 * 60 * 1000, // 5 minutes
max: 5, // 5 OTP attempts
message: 'Too many OTP attempts. Please request a new code.'
});
const downloadLimiter = rateLimit({ // unreasonable traffic
windowMs: 5 * 60 * 1000,
max: 10,
message: 'Too many download requests. Please wait a few minutes.'
})
const deliveryRequestsLimiter = rateLimit({ // unreasonable traffic
windowMs: 5 * 60 * 1000,
max: 10,
message: 'Too many download requests. Please wait a few minutes.'
})
// ---------- Casual protection for email queries ----------
const deliveryCooldown = new Map();
// email -> timestamp
const COOLDOWN_MS = 1 * 60 * 1000;
// cleanup Map
function cleanupCooldown() {
if (deliveryCooldown.size < 100) return;
const now = Date.now();
for (const [email, ts] of deliveryCooldown) {
if (now - ts > COOLDOWN_MS) {
deliveryCooldown.delete(email);
}
}
}
// ---------- One-time table ensure on boot ----------
async function ensureSchema() {
await pool.query(`
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
email TEXT UNIQUE NOT NULL,
password_hash TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
`);
await pool.query(`
CREATE TABLE IF NOT EXISTS register (
id SERIAL PRIMARY KEY,
email TEXT UNIQUE NOT NULL,
name TEXT,
address TEXT,
city TEXT,
country TEXT,
space_knowledge_level TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
`);
await pool.query(`
CREATE TABLE IF NOT EXISTS delivery_requests (
id SERIAL PRIMARY KEY,
email TEXT NOT NULL,
module TEXT NOT NULL,
version TEXT NOT NULL,
use TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
`);
}
ensureSchema().catch(err => {
console.error('Failed to ensure schema:', err);
process.exit(1);
});
// // ---------- Nodemailer setup with SendGrid ----------
// const transporter = nodemailer.createTransport({
// host: 'smtp.sendgrid.net',
// port: 2525,
// secure: false,
// auth: {
// user: 'apikey',
// pass: process.env.SENDGRID_API_KEY
// },
// logger: true,
// debug: true
// });
// // ---------- Nodemailer (SendGrid) ensure on boot ----------
// transporter.verify()
// .then(() => console.log('📮 SendGrid ready'))
// .catch(e => console.error('📮 SendGrid not ready:', e?.response?.body || e)); //e.response.body is just in case of switching into SendGrid Web API, for now we are just using SMTP
let otpStore = {};
// ---------- SIGNUP ----------
app.post('/signup', authLimiter, async (req, res) => {
const { email = '', password = '' } = req.body;
const isValidEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
if (!isValidEmail || !password) {
return res.redirect('/signup.html?error=Invalid email or password');
}
try {
// Check if already exists in DB
const { rows: existing } = await pool.query(
'SELECT id FROM users WHERE email = $1',
[email]
);
if (existing.length > 0) {
return res.redirect('/signup.html?error=Email already exists');
}
// Hash password (we’ll store it in memory for now)
const hash = await bcrypt.hash(password, 12);
// Generate 6-digit OTP
const otp = Math.floor(100000 + Math.random() * 900000).toString(); //range: 100,000 to just under 1,000,000
// Store in memory (in production, you’d want Redis or DB)
otpStore[email] = {
otp,
passwordHash: hash,
expires: Date.now() + 5 * 60 * 1000
};
const mailOptions = {
// from: `${process.env.FROM_NAME || 'SPACEAPP'} <${process.env.FROM_EMAIL}>`,
// from: "SPACEAPP <tanbinhvo.hcm@gmail.com>",
to: email,
subject: "🔐 Verify Your SPACEAPP Account",
html: `
<div style="font-family: 'Arial', sans-serif; font-size: 16px; color: #333; line-height: 1.6; max-width: 600px; margin: auto; padding: 20px; border: 1px solid #e0e0e0; border-radius: 8px;">
<h1 style="color: #4A90E2; font-size: 24px; margin-bottom: 10px;">Verify Your Email</h1>
<p>Hello,</p>
<p>Thank you for signing up for <strong>SPACEAPP</strong>! To complete your registration, please use the following One-Time Password (OTP):</p>
<div style="text-align: center; margin: 20px 0;">
<span style="display: inline-block; font-size: 32px; font-weight: bold; color: #4A90E2; letter-spacing: 4px; padding: 10px 20px; border: 2px dashed #4A90E2; border-radius: 6px;">
${otp}
</span>
</div>
<p style="margin-top: 10px;">This OTP will expire in <strong>5 minutes</strong>.</p>
<p>If you did not initiate this request, you can safely ignore this email.</p>
<hr style="border: none; border-top: 1px solid #e0e0e0; margin: 20px 0;" />
<p style="font-size: 12px; color: #888;">— SPACEAPP Team — Vo Tan Binh</p>
<p style="font-size: 12px; color: #888;">Visit us at <a href="https://spaceappweb.onrender.com/" style="color: #4A90E2;">spaceappweb.onrender.com</a></p>
</div>
`,
replyTo: 'tanbinhvo.hcm@gmail.com'
};
try {
await gmailSend(mailOptions);
console.log('✅ OTP email sent');
req.session.pendingEmail = email;
return res.redirect('/otp.html'); // respond once
} catch (err) {
console.error('❌ OTP Error:', err?.response?.body || err);
return res.status(500).json({ error: "Failed to send email" }); // single response
}
} catch (e) {
console.error('Signup error:', e);
return res.redirect('/signup.html?error=Server+error');
}
});
// ---------- RESEND OTP ----------
app.get('/resend-otp', otpLimiter, async (req, res) => {
const email = req.session.pendingEmail;
if (!email) return res.redirect('/signup.html?error=No pending email');
const record = otpStore[email];
if (!record) return res.redirect('/signup.html?error=Please sign up again');
// Generate new OTP
const otp = Math.floor(100000 + Math.random() * 900000).toString();
otpStore[email].otp = otp;
otpStore[email].expires = Date.now() + 5 * 60 * 1000;
const mailOptions = {
// from: `${process.env.FROM_NAME || 'SPACEAPP'} <${process.env.FROM_EMAIL}>`,
// from: "SPACEAPP <tanbinhvo.hcm@gmail.com>",
to: email,
subject: "🔐 Verify Your SPACEAPP Account",
html: `
<div style="font-family: 'Arial', sans-serif; font-size: 16px; color: #333; line-height: 1.6; max-width: 600px; margin: auto; padding: 20px; border: 1px solid #e0e0e0; border-radius: 8px;">
<h1 style="color: #4A90E2; font-size: 24px; margin-bottom: 10px;">Verify Your Email</h1>
<p>Hello,</p>
<p>Thank you for signing up for <strong>SPACEAPP</strong>! To complete your registration, please use the following One-Time Password (OTP):</p>
<div style="text-align: center; margin: 20px 0;">
<span style="display: inline-block; font-size: 32px; font-weight: bold; color: #4A90E2; letter-spacing: 4px; padding: 10px 20px; border: 2px dashed #4A90E2; border-radius: 6px;">
${otp}
</span>
</div>
<p style="margin-top: 10px;">This OTP will expire in <strong>5 minutes</strong>.</p>
<p>If you did not initiate this request, you can safely ignore this email.</p>
<hr style="border: none; border-top: 1px solid #e0e0e0; margin: 20px 0;" />
<p style="font-size: 12px; color: #888;">— SPACEAPP Team — Vo Tan Binh</p>
<p style="font-size: 12px; color: #888;">Visit us at <a href="https://spaceappweb.onrender.com/" style="color: #4A90E2;">spaceappweb.onrender.com</a></p>
</div>
`,
replyTo: 'tanbinhvo.hcm@gmail.com'
};
try {
await gmailSend(mailOptions);
console.log('✅ OTP email resent');
return res.json({ success: true });
} catch (err) {
console.error('❌ OTP Resend Error:', err?.errors || err);
return res.status(500).json({ error: 'Failed to send email' });
}
});
// ---------- VERIFY ----------
app.post('/verify', verifyLimiter, async (req, res) => {
const { otp } = req.body;
const email = req.session.pendingEmail;
const record = otpStore[email];
if (!record) return res.redirect("/otp.html?error=No OTP found, please sign up again.");
if (Date.now() > record.expires) return res.redirect("/otp.html?error=OTP expired, please sign up again.");
if (record.otp !== otp) return res.redirect("/otp.html?error=Invalid OTP");
try {
// Insert into DB only now
const q = `
INSERT INTO users (email, password_hash)
VALUES ($1, $2)
RETURNING id, email, created_at
`;
const { rows } = await pool.query(q, [email, record.passwordHash]);
// Mark session as logged in
req.session.user = { id: rows[0].id, email: rows[0].email };
// Clean up memory
delete otpStore[email];
return res.redirect("/otp.html?success=1");
} catch (e) {
console.error('Verify error:', e);
return res.status(500).send("Server error during verification");
}
});
// ---------- LOGIN ----------
app.post('/login', authLimiter, async (req, res) => {
const { email = '', password = '' } = req.body;
try {
const { rows } = await pool.query(
'SELECT id, email, password_hash FROM users WHERE email = $1',
[email]
);
if (rows.length === 0) {
return res.redirect('/login.html?error=Wrong email or password');
}
const ok = await bcrypt.compare(password, rows[0].password_hash);
if (!ok) {
return res.redirect('/login.html?error=Wrong email or password');
}
req.session.user = { id: rows[0].id, email: rows[0].email };
// const next = encodeURIComponent('/');
// return res.redirect(`/auth-complete.html?next=${next}`);
return res.redirect('/community.html');
} catch (e) {
console.error('Login error:', e);
return res.redirect('/login.html?error=Server+error');
}
});
// ---------- GG AUTH ----------
app.get('/auth/google', passport.authenticate('google', { scope: ['profile', 'email'] }));
app.get('/auth/google/callback',
passport.authenticate('google', { failureRedirect: '/signup?error=login_failed' }),
(req, res) => {
res.redirect('/community.html');
}
);
// ---------- Session helpers ----------
app.get('/api/isLoggedIn', (req, res) => {
if (req.isAuthenticated()) {
// Passport login (Google)
res.json({ loggedIn: true, user: req.user });
} else if (req.session.user) {
// Normal email/password login
res.json({ loggedIn: true, user: req.session.user });
} else {
res.json({ loggedIn: false });
}
});
app.get('/logout', (req, res) => {
req.logout(() => { // for passport
req.session.destroy(() => {
res.clearCookie('connect.sid');
res.redirect('/');
});
});
});
// ---------- Email ----------
app.post('/freeregister', downloadLimiter, async(req, res) => {
const email = req.body.inputEmail || '';
const firstName = req.body.inputFirstName || '';
const lastName = req.body.inputLastName || '';
const name = (firstName || lastName) ? `${firstName} ${lastName}`.trim() : 'User';
const versionSelected = req.body.flexRadioDefault || 'v5.0';
const address = req.body.inputAddress || '';
const city = req.body.inputCity || '';
const country = req.body.inputCountry || '';
const { spaceKnowledgeLevel } = req.body;
const downloadLinks = {
// 'v4.0': 'https://github.com/Henrycoding-design/SPACEAPPEXE/releases/download/v4.0/SPACEAPPv4.0.zip',
'v4.2': 'https://github.com/Henrycoding-design/SPACEAPPEXE/releases/download/v4.2/SPACEAPPv4.2.zip',
'v5.0': 'https://github.com/Henrycoding-design/SPACEAPPEXE/releases/download/v5.0/SPACEAPPv5.0.zip',
// 'v5.0-beta-1': 'https://github.com/Henrycoding-design/SPACEAPPEXE/releases/download/v5.0-beta-1/SPACEAPPv5.0-beta-1.zip',
'v5.0-beta-5': 'https://github.com/Henrycoding-design/SPACEAPPEXE/releases/download/v5.0-beta-5/SPACEAPP-v5.0-beta-5-Installer-x64.exe',
'v5.5': 'https://github.com/Henrycoding-design/SPACEAPPEXE/releases/download/v5.5.4/SPACEAPP-Stable-v5-5-4-Installer-x64.exe'
};
const downloadLink = downloadLinks[versionSelected] || downloadLinks['v5.5'];
const isValidEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
if (!isValidEmail) return res.status(400).send('Invalid email address');
// prevent casual pings on website
const now = Date.now();
const lastRequest = deliveryCooldown.get(email);
if (lastRequest && now - lastRequest < COOLDOWN_MS) {
const waitSec = Math.ceil((COOLDOWN_MS - (now - lastRequest)) / 1000);
return res.redirect(
`/freeform.html?error=${encodeURIComponent(
`Please wait ${waitSec}s before requesting again.`
)}`
);
}
// mark cooldown
deliveryCooldown.set(email, now);
cleanupCooldown(); // clean up
const q = `
INSERT INTO register (email, name, address, city, country, space_knowledge_level)
VALUES ($1, $2, $3, $4, $5, $6)
ON CONFLICT (email) DO NOTHING
RETURNING id, email, name, created_at
`;
const { rows } = await pool.query(q, [email, name, address, city, country, spaceKnowledgeLevel]);
if (rows.length === 0) {
console.log('Email already registered:', email);
}
const mailOptions = {
// from: `${process.env.FROM_NAME || 'SPACEAPP'} <${process.env.FROM_EMAIL}>`,
// from: "SPACEAPP <tanbinhvo.hcm@gmail.com>",
to: email,
subject: '🚀 Welcome to SPACEAPP!',
html: `
<div style="font-family: Arial, sans-serif; font-size: 16px; color: #333; line-height: 1.6; max-width: 600px; margin: auto; padding: 20px; border: 1px solid #e0e0e0; border-radius: 8px;">
<h1 style="color: #4A90E2; font-size: 24px; margin-bottom: 10px;">
Welcome to SPACEAPP, ${name}!
</h1>
<h2 style="color: #333; font-size: 20px; margin-top: 0;">
🌌 Thank you for downloading!
</h2>
<p>You chose SPACEAPP <strong>${versionSelected}</strong>.
${versionSelected === 'v5.5' ? "SPACEAPP v5.5 is the most refined and internationally capable build to date, engineered for precision and endurance." : "You're all set to begin your journey tracking real-time satellites from Earth."}
</p>
<div style="text-align: center; margin: 20px 0;">
<a href="${downloadLink}" target="_blank" rel="noopener noreferrer"
style="display: inline-block; background-color: #4A90E2; color: #fff; text-decoration: none; font-size: 18px; font-weight: bold; padding: 12px 20px; border-radius: 6px;">
📦 Download SPACEAPP (${versionSelected})
</a>
</div>
<p>If you haven’t yet, remember to register your free API key at
<a href="https://www.n2yo.com/api/" target="_blank" style="color: #4A90E2;">n2yo.com/api</a>
and paste it inside your app when prompted. See more instructions in the README or on our web.
</p>
<p>${versionSelected === "v4.2" ? "Please note that SPACEAPP v4.2 & v4.0 is now considered an earlier release, with several components that have not been updated since October 2025. These versions will be retired and no longer supported after March 2026.":""}
Feel free to contact us with any questions. Enjoy exploring the stars!</p>
<hr style="border: none; border-top: 1px solid #e0e0e0; margin: 20px 0;" />
<p style="font-size: 12px; color: #888; margin: 0;">— SPACEAPP Team — Vo Tan Binh</p>
<p style="font-size: 12px; color: #888;">Visit us at <a href="https://spaceappweb.onrender.com/" style="color: #4A90E2;">spaceappweb.onrender.com</a></p>
<p style="font-size: 12px; color: #888;">Contact: <a href="mailto:tanbinhvo.hcm@gmail.com" style="color: #4A90E2;">tanbinhvo.hcm@gmail.com</a></p>
`,
replyTo: 'tanbinhvo.hcm@gmail.com'
};
// transporter.sendMail(mailOptions, (err, info) => {
// if (err) {
// console.error('❌ Failed to send registration email:', err);
// return res.status(500).send('Failed to send confirmation email');
// }
// console.log('✅ Registration email sent:', info.response);
// res.redirect('/thankyou.html');
// });
try {
await gmailSend(mailOptions);
console.log('✅ Registration email sent');
res.redirect('/thankyou.html');
} catch (err) {
console.error('❌ Failed to send registration email:', err?.errors || err);
return res.status(500).send('Failed to send confirmation email');
}
});
// ---------- Community Page: Direct Delivery ----------
app.post('/api/delivery', deliveryRequestsLimiter, upload.none(), async (req, res) => {
try {
const { email, module, version, use } = req.body;
// Basic validation
const isValidEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
if (!isValidEmail) return res.status(400).send('Invalid email address');
// prevent casual pings on website
const now = Date.now();
const lastRequest = deliveryCooldown.get(email);
if (lastRequest && now - lastRequest < COOLDOWN_MS) {
const waitSec = Math.ceil((COOLDOWN_MS - (now - lastRequest)) / 1000);
return res.status(429).json({
error: `Please wait ${waitSec}s before requesting again.`
});
}
// mark cooldown
deliveryCooldown.set(email, now);
cleanupCooldown();
// Choose the correct download link
const downloadLinks = { // fake links, post github repo for opensrc later once ready, v3.0 is currently in-place, work out the BuyMeACoffee Shop setup for the rest
'api_worker': {'v4.0': 'https://buymeacoffee.com/VoTanBinh/e/485556'},
'core_engine': {'v4.0': 'https://buymeacoffee.com/votanbinh/e/485223', 'v4.2': 'https://buymeacoffee.com/votanbinh/e/485291'},
'map': {'v4.0': 'https://buymeacoffee.com/VoTanBinh/e/485562'},
'full_stack': {'v3.0':'https://github.com/Henrycoding-design/SpaceappwebOpenSrc'},
};
const downloadLink = downloadLinks[module][version] || null;
if (!downloadLinks[module] || !downloadLinks[module][version]){return res.status(400).send('Invalid module/version selection');}
// Optional: insert into DB for record keeping
const q = `
INSERT INTO delivery_requests (email, module, version, use)
VALUES ($1, $2, $3, $4)
RETURNING id, created_at
`;
await pool.query(q, [email, module, version, use || 'N/A']);
// Build email body
const mailOptions = {
to: email,
subject: `🚀 SPACEAPP ${version} – Delivery: ${module} (${version})`,
html: `
<div style="font-family: Arial, sans-serif; font-size: 16px; color: #333; line-height: 1.6; max-width: 600px; margin: auto; padding: 20px; border: 1px solid #e0e0e0; border-radius: 8px;">
<h2 style="color: #3274e7;">Your SPACEAPP open-src ${module} ${version} is ready!</h2>
<p>Thank you for requesting a delivery through the Community Page.</p>
<p><strong>Module:</strong> ${module}</p>
${use ? `<p><strong>Your note:</strong> ${use}</p>` : ''}
<p style="font-size:14px;color:#555;">${version=='v3.0' ? 'Click on the button below to get to our Github opensrc repo!':'Click on the button below to get to our BuyMeACoffee payment system and finish your purchase!'}</p>
<div style="text-align:center;margin:20px 0;">
<a href="${downloadLink}" target="_blank" rel="noopener noreferrer"
style="display:inline-block;background-color:#3274e7;color:#fff;text-decoration:none;font-weight:bold;padding:12px 20px;border-radius:6px;">
📦 Go to ${module} version ${version} </>
</a>
</div>
<p style="font-size:14px;color:#555;">If the button above doesn’t work, use this link: <br>
<a href="${downloadLink}">${downloadLink}</a>
</p>
<p style="font-size:14px;color:#555;">${version=='v3.0' ? `Or you can just clone using Git: git clone ${downloadLink}.git`:''}</p>
<hr style="border:none;border-top:1px solid #ccc;margin:20px 0;">
<p style="font-size:12px;color:#888;margin:0;">— SPACEAPP Team — Vo Tan Binh</p>
<p style="font-size:12px;color:#888;">Contact: <a href="mailto:tanbinhvo.hcm@gmail.com" style="color:#3274e7;">tanbinhvo.hcm@gmail.com</a></p>
</div>
`,
replyTo: 'tanbinhvo.hcm@gmail.com'
};
// Send it (using your same gmailSend() helper)
await gmailSend(mailOptions);
console.log(`✅ Direct delivery email sent to ${email}`);
res.json({ success: true, message: 'Email sent successfully' });
} catch (err) {
console.error('❌ Failed to send delivery email:', err);
res.status(500).json({ success: false, error: 'Internal Server Error' });
}
});
// ---------- Health endpoint to verify DB quickly ----------
app.get('/admin/db-ping', async (req, res) => {
try {
const r = await pool.query('SELECT NOW() as now');
res.json({ ok: true, now: r.rows[0].now });
} catch (e) {
res.status(500).json({ ok: false, error: String(e) });
}
});
app.listen(PORT, () => {
console.log(`Server is running at http://localhost:${PORT}`);
});