Why did the CSS rendering suddenly come to a halt?

I am facing a confusion with EJS. When I make a post request, EJS renders my CSS properly. However, when I try the following code snippet:

exports.resetpassword = async (req, res) => {
  const {id, token} = req.params;
  
  
  const user = await LoginModel.findById(id).exec();
  const secret = process.env.TOKEN_SECRET + user.password
  
  try {
    const payload = jwt.verify(token, secret)
    req.flash('emailReseter', `${user.email}`);
    res.render("resetpassword.ejs", {messageMail: req.flash("emailReseter")});
  } catch (error) {
    console.log(error.message);
  }
  
};

Here's the issue I encounter:

https://i.sstatic.net/D6qSf.png

My CSS file is not applied and I can't figure out the root of the problem.

All my other EJS files are similar, except for the head link, and they apply the CSS correctly.

Answer №1

So far, this is how I have successfully implemented it:

In my routing setup, I included the following:

const router = require("express").Router();
const services = require('../service/render');

router.get("/", services.login);
router.get('/forgot-password', services.forgotpassword);
router.get('/reset-password/:id/:token', services.resetpassword);
router.get('/reset-password', services.resetpasswordredirect)

Inside my render.js file:

exports.resetpassword = async (req, res) => {
  const {id, token} = req.params;
  
  
  const user = await LoginModel.findById(id).exec();
  const secret = process.env.TOKEN_SECRET + user.password
  
  try {
    const payload = jwt.verify(token, secret)
    req.flash('emailReseter', `${user.email}`);
    res.redirect('/reset-password')
  } catch (error) {
    console.log(error.message);
  }
  
};

exports.resetpasswordredirect = async (req,res)=>{
  res.render("resetpassword.ejs", {messageMail: req.flash("emailReseter")});
  
}

Answer №2

After encountering an issue where my CSS was not working when there was an ID in the params, I made a change to my server.js file.

Initially, I had:

app.use(express.static("public"));

And I modified it to:

app.use('/public', express.static("public"));

I also updated all my EJS files, such as transforming:

<link rel="stylesheet" href="css/login.css">

to:

<link rel="stylesheet" href="/public/css/login.css">

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to locate my HTML file in the view section

I have been working on setting up a MEAN app and I've encountered an issue. Everything runs smoothly without the Angular part, but as soon as I integrate Angular, I am unable to view the HTML page located in the "view" folder. Here is my server setup ...

Is there a way to use socket.io to send an emit message to a specific individual client

I have reviewed various solutions but none of them seem to address my issue. I am currently working on developing an online multiplayer chess game. Let's say I have a roster of participants and 10 users are actively listed. My goal is for the admin ...

What benefits come from installing modules such as socket.io/express globally?

Furthermore, I would like to explore the possibility of executing them from the /usr/local/lib directory instead of having to install these modules in the individual folders of each project I am currently managing. ...

Adjusting the screen width to activate a responsive nav bar with a centered title

I'm facing an issue with the alignment of the heading within a navigation bar, causing the links to wrap before the collapse of the nav-bar occurs - https://i.sstatic.net/bKyPM.png I am trying to make the links collapse earlier than they currently d ...

"Encountering an issue with Express.json where it fails to parse the

Receiving JSON POST data from an IoT API that includes multipart form-data. Occasionally, an image file may be included but I only want to focus on the JSON part: POST { host: '192.168.78.243:3000', accept: '*/*', 'content-le ...

Convert the mongoDB information into various collections and transfer it to a fresh server

Challenge: The goal is to synchronize MongoDB data between servers while also making some modifications to certain attributes before transferring. From Server 1 (DB) -> Transform data in collection -> To Server 2 (DB) Desired Outcome: On Server 1 ...

Troubleshooting Bootstrap's Margin Problem

Currently, I am delving into the basics of bootstrap and encountering some challenges with using margin-auto. Specifically, I am working on positioning a navbar by using ml-auto to separate it from the brand, pushing the navbar to the right side of the p ...

What is the method for placing one object within another object?

This is a sample of my data collection: [ { "column1":"data1", "column2":"data2", "column3":[ { "column31":"data31", "column32& ...

CSS: selecting the adjacent siblings of a certain class, starting from the first and

I am working on achieving the following goal: Elements containing values should have a gray 'ribbon'. Elements with values are given a class selected, while elements without any value do not have this class. This is how my HTML code appears: & ...

Dependency on the selection of items in the Bootstrap dropdown menu

I am currently struggling with a few tasks regarding Bootstrap Dropdown Selection and despite looking for information, I couldn't find anything helpful. Check out my dropdown menu Here are the functions I would like to implement: 1) I want the subm ...

Splitting the express instance and routes into two separate server files

Currently, I am in the process of developing a middleware that can run two server files within the same instance while keeping the routes separate. Allow me to elaborate with examples: Directory Structure: /common-server /routers /routes.js /ap ...

My React production build is not currently being served by the Express server

My React app, created with create-react-app, is running smoothly on an express server when I use npm start. However, when I try to run it using npm run build followed by serve -g build, I can only connect to port 5000 on localhost instead of the intended p ...

What is the process for integrating jQuery into a Node project following installation via npm?

After using npm to install jquery (npm install jquery --save), the library was added to my node_modules folder. Now I am unsure of the correct path to use in the script tag on my html page. My directory structure is as follows: -Project Root -node_modu ...

Display an element that has been tucked away, and then bring it to life

Is there a way to implement an animation that causes the hidden form to slide from right to left after the .button class is hidden? I have been able to achieve similar effects individually, but struggle with synchronizing their animations. When the butt ...

The middleware in Expressjs is failing to override the response

My goal is to alter the response body before it's returned, and I attempted a solution from this answer Unfortunately, the solution didn't work as expected. Here's the code I used: app.js function modify(req, res, next) { var json = res ...

Repeating every 3 to 6 months on later.js commencing from a specified date

Currently, I am working on setting up recurring events every 3 and 6 months using the later.js library which can be found at https://github.com/bunkat/later. The code implementation looks like this: // Assuming my value.scheduled_date is set to 2018-09-0 ...

"Ensure that the data in the div is being updated accurately via AJAX in ASP.NET MVC

I'm currently using a div element to display data on page load through AJAX calls. $(document).ready(function () { email_update(); }); function email_update() { $.ajax({ url: '@Url.Action("EmailsList", "Questions")', ...

A new thrower has been created, causing an unhandled 'error' event

Today I encountered a peculiar issue while using Visual Studio Code for Angular applications, something that has never happened to me before! Upon attempting to create a new project with the command 'ng new projects-name', I was faced with an er ...

Toggle class with jquery if the checkbox is checked

I am trying to achieve a simple task using jQuery. I have a checkbox inside a box, and I want to toggle a class on the box with a transition when the checkbox is checked. However, my code is not working as expected. Here is what I have: $(document).ready( ...

Container for grid template columns and responsive window in a single row

Imagine having around 250 divs with the class slider-item styled in a certain way. You have a responsive grid in CSS called A which arranges these divs as columns/items when the window resizes, with a minimum item width of 240px. Check out how it looks bel ...