Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 48 additions & 22 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,66 @@
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const helmet = require("helmet");
const morgan = require("morgan");
const rateLimit = require("express-rate-limit");
const http = require("http");
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const helmet = require('helmet');
const morgan = require('morgan');
const rateLimit = require('express-rate-limit');
const http = require('http');
const path = require('path');

Check warning on line 8 in app.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `node:path` over `path`.

See more on https://sonarcloud.io/project/issues?id=temichelle13_StudyPlanner&issues=AZz5cbRGwNKr22krPRBd&open=AZz5cbRGwNKr22krPRBd&pullRequest=63

const app = express();
const port = process.env.PORT || 3000;
// Middleware for parsing JSON and urlencoded data

app.use(express.json());
app.use(express.urlencoded({ extended: true }));

app.use(helmet()); // Security Headers
app.use(morgan("short"));
// Rate Limit for brute force attacks
app.use(cors());
app.use(helmet());
app.use(morgan('short'));
app.use(
rateLimit({
windowMs: 60 * 60 * 1000, // 1 hour
windowMs: 60 * 60 * 1000,
max: 100,
}),
);

app.use(express.static(path.join(__dirname)));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Serve static assets from a dedicated public directory

Using express.static(path.join(__dirname)) exposes the entire repository tree as web-accessible static files (for example source files and backup scripts under the project root), which unnecessarily leaks implementation details and increases attack surface in production. Static hosting should be limited to a specific client-assets directory instead of the repo root.

Useful? React with 👍 / 👎.


app.post('/api/discovery-contact', (req, res) => {
const { name, email, goal, timeline, message } = req.body;

if (!name || !email || !goal || !timeline || !message) {
return res.status(400).json({ error: 'All discovery contact fields are required.' });
}

return res.status(201).json({ message: 'Discovery contact submitted successfully.' });
});

app.post('/api/subscribe', (req, res) => {
const { email } = req.body;

if (!email) {
return res.status(400).json({ error: 'Email is required.' });
}

return res.status(201).json({ message: 'Subscription successful.' });
});

app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});

const server = http.createServer(app);

process.on("uncaughtException", (error) => {
console.error("Uncaught exception:", error);
process.on('uncaughtException', (error) => {
console.error('Uncaught exception:', error);
server.close(() => process.exit(1));
});

server.listen(port, () => {
console.log("Server is started on port " + port);
process.on('unhandledRejection', (error) => {
console.error('Unhandled rejection:', error);
});
process.on("unhandledRejection", (error) => {
console.error("Unhandled Rejection:", error);
});
process.on("rejectionHandled", (error) => {
console.error("Rejection handled:", error);

server.listen(port, () => {
console.log(`Server is started on port ${port}`);
});

module.exports = app;
272 changes: 60 additions & 212 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,240 +1,88 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Study Planner</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Study Planner</h1>
</header>
<main>
<section id="schedule">
<h2>Your Schedule</h2>
<!-- Schedule content goes here -->
</section>
<section id="tasks">
<h2>Your Tasks</h2>
<!-- Task list and management interface goes here -->
<div id="taskForm">
<form>
<!-- Form content for adding tasks -->
</form>
</div>
<div id="taskList">
<!-- Dynamic task list will be rendered here -->
<ul id="tasksList"></ul>
</div>
</section>
</main>
<footer>
<p>&copy; 2023 Study Planner</p>
</footer>
<script src="main.js"></script>
<script>
// Example fetch request to an API endpoint
fetch('/api/tasks')
.then(response => response.json())
.then(data => {
// Handle data (tasks) here
console.log(data);
})
.catch(error => {
console.error('Error fetching tasks:', error);
});
</script>
<script>
// Function to fetch and display tasks
function fetchAndDisplayTasks() {
fetch('/api/tasks')
.then(response => response.json())
.then(tasks => {
const tasksList = document.getElementById('tasksList');
tasksList.innerHTML = ''; // Clear existing tasks
tasks.forEach(task => {
const taskItem = document.createElement('li');
taskItem.textContent = task.title;
tasksList.appendChild(taskItem);
});
})
.catch(error => {
console.error('Error fetching tasks:', error);
});
}
// Call the function on page load
document.addEventListener('DOMContentLoaded', fetchAndDisplayTasks);
</script>
</body>
</html>
=======


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Study Planner</title>
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Add viewport meta element -->
<title>Document</title>
</head>
<body>
<header>
<h1>Study Planner</h1>
</header>
<main>
<section id="schedule">
<h2>Your Schedule</h2>
<!-- Schedule content goes here -->
</section>
<section id="tasks">
<h2>Your Tasks</h2>
<!-- Task list and management interface goes here -->
<div id="taskForm">
<form>
<!-- Form content for adding tasks -->
</form>
</div>
<div id="taskList">
<!-- Dynamic task list will be rendered here -->
</div>
</section>
</main>
<footer>
<p>&copy; 2023 Study Planner</p>
</footer>
<script src="main.js"></script>

</body>
</html>

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Added viewport meta element -->
<title>Document</title>
</head>
<body>

</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>

</head>
<body>

</body>
</html>
<body>

</body>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Add viewport meta element -->
<title>Document</title>
</head>
<body>

</body>

</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Added viewport meta element -->
<title>Document</title>
</head>
<body>

</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>

</head>
<body>

</html>

<script>
// Example fetch request to an API endpoint
fetch('/api/tasks')
.then(response => response.json())
.then(data => {
// Handle data (tasks) here
console.log(data);
})
.catch(error => {
console.error('Error fetching tasks:', error);
});
</script>

<script>
// Function to fetch and display tasks
function fetchAndDisplayTasks() {
fetch('/api/tasks')
.then(response => response.json())
.then(tasks => {
const tasksList = document.getElementById('tasksList');
tasksList.innerHTML = ''; // Clear existing tasks
tasks.forEach(task => {
const taskItem = document.createElement('li');
taskItem.textContent = task.title;
tasksList.appendChild(taskItem);
});
})
.catch(error => {
console.error('Error fetching tasks:', error);
});
}

// Call the function on page load
document.addEventListener('DOMContentLoaded', fetchAndDisplayTasks);
</script>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Study Planner</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="style.css" />
</head>
<body>
<header>
<h1>Study Planner</h1>
</header>

<main>
<section id="schedule">
<h2>Your Schedule</h2>
<p>Plan your upcoming sessions and keep your progress on track.</p>
</section>

<section id="tasks">
<h2>Your Tasks</h2>
<div id="taskForm">
<form id="taskFormElement">
<input type="text" id="taskTitle" placeholder="Title" required />
<input type="text" id="taskDescription" placeholder="Description" required />
<input type="date" id="taskDueDate" required />
<label for="taskTitle">Title</label>
<input type="text" id="taskTitle" name="title" placeholder="Task title" required />

<label for="taskDescription">Description</label>
<input type="text" id="taskDescription" name="description" placeholder="Task description" required />

<label for="taskDueDate">Due date</label>
<input type="date" id="taskDueDate" name="dueDate" required />

<button type="submit">Add Task</button>
</form>
</div>
<div id="taskList"></div>
</section>

<section id="discovery-contact">
<h2>Discovery Contact Form</h2>
<form id="discoveryContactForm" novalidate>
<label for="contactName">Full name</label>
<input type="text" id="contactName" name="name" required />

<label for="contactEmail">Email</label>
<input type="email" id="contactEmail" name="email" required />

<label for="contactGoal">Primary goal</label>
<select id="contactGoal" name="goal" required>
<option value="" disabled selected>Select your goal</option>
<option value="time-management">Improve time management</option>
<option value="exam-prep">Exam preparation</option>
<option value="course-planning">Course planning</option>
<option value="accountability">Accountability coaching</option>
</select>

<label for="contactTimeline">Timeline</label>
<select id="contactTimeline" name="timeline" required>
<option value="" disabled selected>Select a timeline</option>
<option value="asap">As soon as possible</option>
<option value="2-weeks">Within 2 weeks</option>
<option value="1-month">Within a month</option>
</select>

<label for="contactMessage">Message</label>
<textarea id="contactMessage" name="message" rows="4" required></textarea>

<button type="submit">Send Discovery Request</button>
<p id="discoveryContactStatus" class="form-status" aria-live="polite"></p>
</form>
</section>
</main>

<footer>
<p>&copy; Study Planner</p>
<form id="footerSubscribeForm" class="subscribe-form" novalidate>
<label for="subscribeEmail">Subscribe for study tips</label>
<div class="subscribe-row">
<input type="email" id="subscribeEmail" name="email" placeholder="you@example.com" required />
<button type="submit">Subscribe</button>
</div>
<p id="subscribeStatus" class="form-status" aria-live="polite"></p>
</form>
</footer>

<script src="main.js"></script>
</body>
</html>
</html>
Loading
Loading