Monday 30 January 2017

CSS and Javascript files being blocked due to MIME type mismatch

First off, I'm sorry for posting here. But I'm running out of places I know of where I can ask for help. If I'm posting this in the wrong place, I'm sorry, and I would be greatfull if you could point me somewhere where I can post it.I have been getting this error of The resource from “[URL and name of file]” was blocked due to MIME type mismatch (X-Content-Type-Options: nosniff). for all of my CSS and Javascript files.The setup I currently have is a node.js server using Express and Express-Handlebars for routing and templates. I'm sure the issue is down to my routing of files which would have requests of dealing with routes like /movies/:id or /search/query:. I have kinda fixed the issue by creating two links to CSS and Javascript files in my main.hbs file (The one which is the default main template), one with a link from / and another for /something/something. Terrible practice I know. But up until now, it worked.But this is why I am asking for help in solving the MIME type mismatch error once and for all. Because when I have uploaded it to my Digital Ocean server, it won't work at all. And I have no clue on how to fix it.My file structure is as follows:/ views/ css/ js/ layouts/ main.hbs index.js In index.js, I have the code to setup handlebars and some code managing CSS and Javascript files.app.engine('.hbs', exphbs({ defaultLayout: 'main', extname: '.hbs', layoutDir: path.join(__dirname, 'views/layouts') })); app.set('view engine', '.hbs'); app.set('views', path.join(__dirname, 'views')); app.use(express.static(__dirname + '/views')); An example of an route would beapp.get('/search/:query', (request, response) => { // Code goes here }); I'm genuinely stuck on what to do. I feel like I have been to all corners of the internet and I cant find any solution to my issue. Its frustrating and bringing me down massively. I feel that there is nowhere to help me. I know there are more important things, but I'm pissed that I can't find anywhere (or anyone) who is having the same issue I have. Let me know If you need any more context.ThanksEDIT I have gotten that desperate, I will give Reddit Gold to whoever will help me fix my issue.

Submitted January 30, 2017 at 11:28PM by McMrChip

No comments:

Post a Comment