Reputation: 965
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 be
app.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.
Any help would be appreciated.
Upvotes: 3
Views: 9512
Reputation: 17
This has something to do with the dots. I had the same problem. I found out that all my files were in the form of filename.min.js . So I removed the first dot and changed the filename to filenamemin.js and it worked. Maybe express reads everything after the first dot as the file extension.
Upvotes: 0