css 在 heroku.but 中部署时未应用样式表在本地主机中有效 node.js
css stylesheet not applied when it is deployed in heroku.but works in localhost node.js
const express = require('express');
const nodemailer = require('nodemailer');
const app = express();
const path = require('path');
const PORT = 5000;
app.use(express.json());
app.use(express.urlencoded({
extended: false
}));
//app.use(express.static(path.join(__dirname, '/public')));
app.use(express.static('public'));
<link rel="stylesheet" href="stylesheets/main.css" type="text/css" />
enter image description here
拒绝应用来自 'https://selvamlicagent.herokuapp.com/stylesheets/main.css' 的样式,因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型,并且启用了严格的 MIME 检查。
当您将 public
(小写 p
)传递给 express.static()
时,您的 public 文件夹被命名为“Public”。重命名您的文件夹以与代码完全匹配,然后重试。
const express = require('express');
const nodemailer = require('nodemailer');
const app = express();
const path = require('path');
const PORT = 5000;
app.use(express.json());
app.use(express.urlencoded({
extended: false
}));
//app.use(express.static(path.join(__dirname, '/public')));
app.use(express.static('public'));
<link rel="stylesheet" href="stylesheets/main.css" type="text/css" />
enter image description here
拒绝应用来自 'https://selvamlicagent.herokuapp.com/stylesheets/main.css' 的样式,因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型,并且启用了严格的 MIME 检查。
当您将 public
(小写 p
)传递给 express.static()
时,您的 public 文件夹被命名为“Public”。重命名您的文件夹以与代码完全匹配,然后重试。