Skip to content

Commit aba4308

Browse files
add landing page and routes
1 parent 9178903 commit aba4308

File tree

5 files changed

+658
-0
lines changed

5 files changed

+658
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

app.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const express = require('express');
2+
const path = require('path');
3+
const fs = require('fs');
4+
const app = express();
5+
6+
// Define the path to the projects directory
7+
const projectsDir = path.join(__dirname, 'projects');
8+
9+
// Serve the list of project directories as a JSON array
10+
app.get('/projects', (req, res) => {
11+
fs.readdir(projectsDir, (err, files) => {
12+
if (err) {
13+
res.status(500).send('Unable to scan projects directory.');
14+
return;
15+
}
16+
const projects = files.filter(file => fs.statSync(path.join(projectsDir, file)).isDirectory());
17+
res.json(projects);
18+
});
19+
});
20+
21+
// Loop through each project folder and create a route for it
22+
fs.readdirSync(projectsDir).forEach(folder => {
23+
const projectPath = path.join(projectsDir, folder);
24+
if (fs.statSync(projectPath).isDirectory()) {
25+
app.use(`/${folder}`, express.static(projectPath));
26+
}
27+
});
28+
29+
// Serve the landing page at the root
30+
app.get('/', (req, res) => {
31+
res.sendFile(path.join(__dirname, 'index.html'));
32+
});
33+
34+
// Start the server
35+
const PORT = process.env.PORT || 3000;
36+
app.listen(PORT, () => {
37+
console.log(`Server is running on http://localhost:${PORT}`);
38+
});
39+

index.html

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>My Projectstitle>
7+
<style>
8+
body {
9+
font-family: Arial, sans-serif;
10+
text-align: center;
11+
margin: 50px;
12+
background-color: #f4f4f4;
13+
}
14+
h1 {
15+
font-size: 3em;
16+
margin-bottom: 20px;
17+
color: #333;
18+
}
19+
ul {
20+
list-style-type: none;
21+
padding: 0;
22+
}
23+
li {
24+
margin: 10px 0;
25+
}
26+
a {
27+
text-decoration: none;
28+
font-size: 1.5em;
29+
color: #3498db;
30+
transition: color 0.3s ease;
31+
}
32+
a:hover {
33+
color: #2c3e50;
34+
}
35+
style>
36+
head>
37+
<body>
38+
<h1>Welcome to My Projectsh1>
39+
<ul id="projects-list">
40+
41+
ul>
42+
43+
<script>
44+
// Project folders will be added dynamically by the server (Express.js)
45+
fetch('/projects')
46+
.then(response => response.json())
47+
.then(projects => {
48+
const list = document.getElementById('projects-list');
49+
projects.forEach(project => {
50+
const listItem = document.createElement('li');
51+
const link = document.createElement('a');
52+
link.href = `/${project}`;
53+
link.textContent = project.replace('_', ' ').toUpperCase();
54+
listItem.appendChild(link);
55+
list.appendChild(listItem);
56+
});
57+
})
58+
.catch(error => console.error('Error fetching project list:', error));
59+
script>
60+
body>
61+
html>
62+

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "html-css-javascript-projects-for-beginners",
3+
"version": "1.0.0",
4+
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"express": "^4.19.2"
14+
}
15+
}

0 commit comments

Comments
 (0)