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:

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

angular contains vulnerabilities of a moderate severity level

I am encountering an issue while trying to set up the json server for a web application I am developing using Angular. Can someone provide assistance in resolving this problem? The following dependencies are at risk due to vulnerable versions: node_m ...

Can an error be thrown from a catch block within a Promise in a NodeJs environment?

While working with NextJs, I encountered an issue in my API code. In one of my api pages (/api/sendData.ts), there is a method call process() that belongs to a separate class platform.ts. This is the structure of my API code (in sendData.ts): try { pla ...

Attempted to run npm install -g truffle but encountered a gyp error

I attempted npm node-gyp -g without success. The goal is to install truffle on my Mac running macOS Catalina, with node version 16.13.1 and npm version 8.1.2. npm ERR! code 1 npm ERR! path /usr/local/lib/node_modules/truffle/node_modules/ganache/node_mod ...

Encountering an incorrect number of parameters for "undefined" during the deployment of a smart contract

I am facing an issue while attempting to deploy my first Voting contract on the testRPC. The error seems to arise from the arguments parameter in the code snippet below. When I tried passing an empty array, it gave an error stating "Got 0 expected 1!". Si ...

Is the Packery image grid only functional when the background image is specified in CSS and not in JavaScript? Perhaps we need to look into using Await/Sem

I've successfully implemented a packery image grid that is responsive and functional when the background image in the .item-content section is defined in the CSS file: http://codepen.io/anon/pen/eJdapq .item-content { width: 100%; height: 100%; ...

Clicking on the menu in mobile view will cause it to slide upward

I have implemented sticky.js on my website and it is working well. However, when I resize the browser to mobile view and click the main menu button, it goes up and I am unable to close it. I have to scroll up to see it again. How can I make it stick to the ...

Unusual behavior of middleware in express 4 causing a strange dynamic effect

I've encountered an issue where a dynamically created middleware in an Express 4 route is not getting called and causing a timeout. 'use strict'; var bodyParser = require( 'body-parser' ); var logger = require( './logger&apo ...

struggle to locate / Node.js Error

I followed the tutorial located at and implemented the following code. // Module dependencies. var application_root = __dirname, express = require( 'express' ), //Web framework path = require( 'path' ), //Utilities for dealing with fi ...

Ways to incorporate a dictionary into your website's content

I am in the process of developing a website for educational purposes while also honing my web programming skills. On this website, I have encountered some complicated terms that may be difficult for users to understand, so I want to implement a tooltip/mod ...

Jenkins encounters error during NPM update

Encountering an error with NPM update while attempting to compile the code in Jenkins. All dependencies listed in the package.json file are already available in a private repository. Executing npm update in /var/www-etc/etc/releases/source/2018012599999 ...

Animating a CSS overlay

My goal is to design an overlay using the following HTML and CSS code snippets div.relative { position: relative; width: 400px; height: 200px; border: 3px solid #73AD21; } div.absolute { position: absolute; top: 50%; right: 0; width: 20 ...

What is the best way to maintain consistent scaling for elements of varying widths and heights?

I'm searching for a method to evenly scale my elements regardless of their width and height. I don't want them to be proportional to their size. Check out the JSFiddle version body, html { height: 100%; width: 100%; margin: 0; backgro ...

The background is set and the vertical scrolling overflow is enabled

My website has an image set as the background, with a fixed position and overflow-y to allow scrolling. However, I have encountered an issue where the height of the image is causing problems on certain displays and resolutions. To temporarily fix this pro ...

Is it possible to include a local directory as a dependency in the package.json file

As I work on developing an npm package alongside its application, I find myself constantly making small changes to the package. Each time I make a change, I want to run the application again for testing purposes. The package is included as a dependency in ...

Issues with Bootstrap's hamburger menu not functioning properly when clicked

Can't seem to get my hamburger button working. I've followed the bootstrap documentation and ensured that Bootstrap and jQuery are in the correct order, but still no luck. Any suggestions on what could be causing this issue? Are my links misplace ...

"Placing the save button on top of a div - a step

I am trying to position a div with an ID below a save button in my HTML code. The current setup looks like this: <button id="item_new" data-action="create" class="floating-button mdl-button mdl-js-button mdl-button--fab mdl-js-ripple-effect mdl-button- ...

Styling with CSS 3: Adding Shadows and Rounded Edges

Encountered an intriguing discovery and I'm hoping you can shed some light on it. Here's the code in question: width:940px; margin:0 auto; padding:13px 29px 39px 31px; background:#fff; -webkit-border-radius:10px; -moz-border-radius:1 ...

Arrange a pair of div containers side by side on the webpage without the need to alter the existing

Is there a way to align these two div side by side? <div class="main_one"> <div class="number_one">Title A</div> </div> <div class="main_two"> <div class="number_two">Title B</div> </div> <div class=" ...

Encountering a syntax error when running newman on an Ubuntu system

Just starting out with newman and looking to integrate it into my CI\CD pipeline (specifically VSTS). I've been able to export my collection.json and env.json files, but running the tests is giving me some trouble. newman run Dev-.postman_collect ...

Show off a sleek slider within a Bootstrap dropdown menu

Is there a way to display a sleek slider within a Bootstrap dropdown element? The issue arises when the slider fails to function if the dropdown is not open from the start, and the prev/next buttons do not respond correctly. For reference, here is my curr ...