Skip to content

Commit 2433ac0

Browse files
committed
Updated index.js
1 parent 0374e84 commit 2433ac0

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

index.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
const express = require('express'); // Duh
2-
1+
const express = require('express'); // Import Express.js
32
const app = express();
4-
app.use(express.static('public'));
3+
app.use(express.static('public')); // Serve static files from the 'public' directory
54

5+
// Root route
66
app.get('/', function (req, res) {
7-
if (req.header('X-Replit-User-Id')) { // Check to see if the user is logged in...
8-
res.redirect(`/home/?user=${req.header('X-Replit-User-Name')}`); // They are logged in, redirect them to the home page.
7+
if (req.header('X-Replit-User-Id')) { // Check if the user is logged in
8+
res.redirect(`/home/?user=${req.header('X-Replit-User-Name')}`); // Redirect to home page with user name as query parameter
99
} else {
10-
res.sendFile(__dirname + '/public/login.html'); // Send a login page if they are not.
10+
res.sendFile(__dirname + '/public/login.html'); // Send login page if user is not logged in
1111
}
1212
});
1313

14+
// Home route
1415
app.get('/home', function (req, res) {
15-
// You could do anything you want here...
16-
// You might want to secure it a little, so people have to be logged in to view the page.
17-
res.send(`<h1>Hello, ${req.query.user}</h1>`); // You could modify this to render a template, or store the user in a database...
16+
if (!req.query.user) { // Ensure user parameter is present
17+
res.redirect('/'); // Redirect to login if user parameter is missing
18+
} else {
19+
res.send(`<h1>Hello, ${req.query.user}</h1>`); // Send a personalized greeting to the user
20+
}
1821
});
1922

20-
app.listen(8080, function () { // Start the server
23+
// Start the server on port 8080
24+
app.listen(8080, function () {
2125
console.log('Server up!');
2226
});

0 commit comments

Comments
 (0)