我的css和html鏈接在服務器中不起作用
我使用node.js和express來運行我的服務器
我的server.js是
const http = require('http')
const fs = require('fs')
var express = require('express');
var app = express();
app.use(express.static('public'));
app.set('veiw engine', 'ejs');
app.engine('html', require('ejs').renderFile)
app.use(express.static(__dirname + '/public'));
const port = 8001 // ??? ?? ??? ?????.
const server = http.createServer(function(request, response) {
console.log('??? ????? ???? ' + request.connection.remoteAddress)
const content = fs.readFileSync('public/main.html')
response.writeHead(200, { 'Content-Type': 'text/html' }) // ?? ??? ????.
response.write(content) // ??? ??? ????.
response.end() // ??? ?????.
})
// ??? ??? ?????.
server.listen(port, function() {
console.log('??? ???????!')
})
我的main.html是
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>main</title>
<link rel="stylesheet"
href="main.css">
</head>
<body>
<div class="container">
<header>
<p>FISMA</p>
<ul>
<li><a href="main.html">?</a></li>
<li><a href="./????2.0/????.html">?? ???</a></li>
<li><a href="./????/????.html">?? ??</a></li>
<li><a href="./?????/?????.html">??? ??</a></li>
<li><a href="./????/????.html">? ???</a></li>
</ul>
</header>
<section>
</section>
<footer>
made by FISMA, Hanyang University, Department of Physics
</footer>
</div>
</body>
</html>
我試著添加 app . use(express . static(' public ')); 還有server.js里的其他,但是不行。
當我只是執行html時,它工作得很好,但當我上傳到服務器并執行時,它就不工作了