Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server Files #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

justuravgcoder
Copy link
Collaborator

First Pull Request

server.js Outdated Show resolved Hide resolved
server.js Outdated Show resolved Hide resolved
server.js Outdated Show resolved Hide resolved
server.js Outdated Show resolved Hide resolved
app.listen(PORT, () => console.log(`Running on port number: ${PORT}`));

app.post('/login', (req, res) => {
const { username, password } = req.body;
Copy link
Owner

Choose a reason for hiding this comment

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

check if username and password are provided. If not return 400 response with message to let user know of the missing fields

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added the required changes

server.js Outdated
res.cookie('auth', 'loggedin', { httpOnly: true });
res.status(201).send("User Successfully Logged in");
} else {
res.status(404).send("No user found with these credentials");
Copy link
Owner

Choose a reason for hiding this comment

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

explore http repsonse codes and use a better response code here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated with better code

server.js Outdated
});

app.get('/getallrepos', (req, res) => {
if (req.cookies.auth === "loggedin") {
Copy link
Owner

Choose a reason for hiding this comment

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

explore express middlewares and use an auth middleware instead of checking of the cookie for each route.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added the auth middleware wherever necessary

server.js Outdated
Comment on lines 119 to 122
if (specialwords(data.repo_name) || specialwords(data.repo_author) || specialwords(data.details)) {
res.status(400).send("Please avoid special characters in Name, Author, and Details");
} else if (typeof data.year_created !== "number" || typeof data.commits !== "number") {
res.status(400).send("Please use numbers when providing commits and year created");
Copy link
Owner

Choose a reason for hiding this comment

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

create an express middleware to handle validation logic and use the middleware chaining.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Made the changes by including a repovalidation middleware function and chained it to the create-repo route

Comment on lines +125 to +129
let name = req.query.name;
if (name) {
if (specialwords(name)) {
res.status(400).send("Please avoid using special characters");
} else {
Copy link
Owner

Choose a reason for hiding this comment

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

Lets move this to middleware as well. In this middleware you can do req.name = req.query.name and next middleware will have access to req.name. Similarly create sanitization middleware for all the routes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants