I am attempting to add node.js
to my webpage project. I have working .html
, .js
, and .css
files. I then added a node.js
file, and ran it with node node.js
and the .html
loads, but I get, in firefox:
The resource from “http://localhost:2020/path/to/public/website.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
How do I get the .css
and .js
files to import properly? (If I just open the .html
, the files are correct.
testFunction = function() { alert("I work!"); }
* { background-color: rgb(51, 45, 45); color: rgb(163, 149, 149); font-family: cursive; font-size: larger; } h1 { text-align: center; }
<!DOCTYPE html> <html> <head> <title>Index</title> <link rel="stylesheet" type="text/css" href="./website.css"> </head> <body> <h1>Thanks for looking at me</h1> <p><span id="story">This is a story</span></p> <button onclick="testFunction()">This is a useless button</button> <script type="text/javascript" src="./site.js"></script> </body> </html>
var io = require('socket.io');
var url = require('url');
var express = require('express');
var http = require('http');
var app = express();
var server = http.createServer(app);
var socket = io.listen(server);
app.engine('.html', require('ejs').__express);
app.set('views', __dirname + '/public');
app.set('view engine', 'html');
app.get('/', function(req, res) {
res.sendFile(__dirname + '/public/index.html');
});
app.listen(2020);
Seems yo have no route to serve css/js with express. . Here is a doc to serve static files with express
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.