File structure
index.js:
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(
bodyParser.urlencoded({
extended: true,
})
);
chat.ejs
<body>
<h1><%= (roomName) %></h1>
<div id="video-grid">
</div>
<script src="script.js"></script>
</body>
while loading, error displayed
"The resource from “http://localhost:5000/chat/Aishu%20study/Aneesa/script.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff)."
It works if I keep everything in the same html file. can someone help me with this? I'm not sure what the problem is
You should include Your public path like this:
app.use(express.static(__dirname+ '/public'));
And then implement your scripts and styles like this:
<script src="/script.js">
The issue lays in incorrect pathing in your application, you see the way you included script.js in the html file may have been correct if the paths were relative to the same folder. To be precise the ways you could define it are
The one you used "script.js" file is located in the same folder as the current page, it does not work the way you want it, since you are accessing the script tag from the localhost:5000/chat/Aishu%20study/Aneesa/xx
url
<script src="script.js">
The "script.js" file is located in the scripts folder in the current folder
<script src="scripts/script.js">
The "script.js" file is located in the scripts folder at the root of the current web
<script src="/scripts/script.js">
The "script.js" file is located in the folder one level up from the current folder
<script src="../script.js">
And lastly the one you should be using, the "script.js" file is located at the root of the current web
<script src="/script.js">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With