When I add the ':username' route param to my GET path (in code below), I start running into this error:
Expected a JavaScript module script but the server responded with a MIME type of "text/html".
My dashboarduser.js is defined in my dashboarduser.ejs I have attempted to use the '.mjs' extension as per the MDN doc recommendation, as well as setting the headers to ("Content-Type", text/html) & also text/javascript, but to no remedy.
Here are my two route handlers that I use:
app.get(`/dashboarduser/:username`, isLoggedIn, (req, res) => {
res.setHeader("Content-Type", "text/html")
res.render('dashboarduser', {user: req.user.username})
console.log("req.user: " + req.user.username);
})
app.post('/login', passport.authenticate('local', {
// successRedirect: `/dashboarduser`,
failureRedirect: '/login',
failureFlash: true,
}), (req, res) => {
res.redirect('/dashboarduser/' + req.user.username)
});
When a user logs in, they are taken to their dashboard with their req.params. E.g. website.com/dashboarduser/johndoe, but there is the lingering error in the console. I am running a local strategy via passport-local, and using passport local mongoose for a local DB. Ultimately I want users to be able to have their own events they set up, and I want them to be able to easily share a URL to invite others. Are these route params necessary or will the local storage take care of this?
Thanks for reading~