剛剛在我的學校啟動 Express 服務器模塊。我做了一個非常簡單的網站只是為了嘗試一下,但似乎 css 文件沒有被執行(在 chrome 的終端 cl 中檢查)。拒絕應用“http://localhost:3000/public/style.css”中的樣式,因為其 MIME 類型(“text/html”)不是受支持的樣式表 MIME 類型,并且啟用了嚴格的 MIME 檢查。家:26獲取http://localhost:3000/public/einstein-home.jpg 404(未找到)const express = require('express'); const app = express(); app.use(express.static('public')); app.get('/home', (request, response) => { console.log('dirname', __dirname); response.sendFile(__dirname + '/views/home.html') }); app.get('/about', (request, response) => { console.log('dirname', __dirname); response.sendFile(__dirname + '/views/about.html') }); app.get('/works', (request, response) => { console.log('dirname', __dirname); response.sendFile(__dirname + '/views/works.html') }); app.listen(3000, () => { console.log('Website about Einstein'); });body { font-family: Verdana, Geneva, Tahoma, sans-serif; background-color: #f2f2f2; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-style: normal; font-weight: 200;}.container { width: 90%; margin-left: auto; margin-right: auto; height: 600px; background-color: #FFFFFF;}header { width: 100%; height: 8%; background-color: #52bad5; border-bottom: 1px solid #2C9AB7;}nav { float: right; width: 50%; text-align: right; margin-right: 25px;}header nav ul { list-style: none; float: right;}nav ul li { float: left; color: #FFFFFF; font-size: 14px; text-align: left; margin-right: 25px; letter-spacing: 2px; font-weight: bold; transition: all 0.3s linear;}ul li a { color: #FFFFFF; text-decoration: none;}ul li:hover a { color: #2C9AB7;}.text { width: 90%; text-align: justify; font-weight: lighter; line-height: 25px; float: left; padding-left: 20px; padding-right: 20px; color: #A3A3A3;}
Express Server 的 MIME 類型問題('text/html')
楊魅力
2023-07-06 15:02:29