如何解决MIME类型问题?

时间:2020-08-09 17:02:12

标签: javascript css node.js express ejs

嘿,怎么了?

我正在使用express.js在一个网站上工作。我当前所有的ejs文件都可以访问css文件,除了一个文件外,我没有任何问题。问题:

Refused to apply style from 'http: // localhost: 8080 / dashboard / public / css / style.css' because its MIME type ('text / html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

但是,我已经声明了包含css文件的文件夹。 (所有文件都在同一个CSS文件中。)

无法检测到相关CSS的ejs文件:

<%- include("partials/header", { bot, user, path, title: "settings" }) %>

<% if (alert) { %>
  <p><%= alert %></p><br>
<% } %>

<h1><%= guild.name %></h1>
  <img src="<%= guild.iconURL %>">
<form style="margin-top: 1em;" method="POST"> <!-- method="post" tiggers a POST request to the same url with the body of the form control inputs -->
  <p>Prefix:</p>
  <input type="text" name="prefix" value="<%= settings.prefix %>" placeholder="Votre prefix"><br><br>
  <button type="submit">Sauvegarder</button>
</form>

<%- include("partials/footer") %>

css文件在头文件中这样声明:

<link rel="stylesheet" href="public/css/style.css">

现在这是我的js文件:(这不是整个文件)

  passport.use(new Strategy({
    clientID: config.id,
    clientSecret: config.clientSecret,
    callbackURL: `${config.domain}${config.port == 80 ? "" : `:${config.port}`}/callback`,
    //`${config.domain}${config.port == 80 ? "" : `:${config.port}`}/callback`
    scope: ["identify", "guilds"]
  },
  (accessToken, refreshToken, profile, done) => { // eslint-disable-line no-unused-vars
    // On login we pass in profile with no logic.
    process.nextTick(() => done(null, profile));
  }));

  // We initialize the memorystore middleware with our express app.
  app.use(session({
    store: new MemoryStore({ checkPeriod: 86400000 }),
    secret: "#@%#&^$^$%@$^$&%#$%@#$%$^%&$%^#$%@#$%#E%#%@$FEErfgr3g#%GT%536c53cc6%5%tv%4y4hrgrggrgrgf4n",
    resave: false,
    saveUninitialized: false,
  }));

  // We initialize passport middleware.
  app.use(passport.initialize());
  app.use(passport.session());


  // We initialize the public folder (with the css file)
  app.use("/public", express.static(path.resolve(`${dataDir}${path.sep}public`)));

  // We bind the domain.
  app.locals.domain = config.domain.split("//")[1];

  // We set out templating engine.
  app.engine("html", ejs.renderFile);
  app.set("view engine", "html");

  // We initialize body-parser middleware to be able to read forms.
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({
    extended: true
  }));

我想我理解为什么这不起作用。所述网页是基于不和谐服务器的ID(生成)的页面。 (这是用于仪表板的。)

所以我想知道,为什么问题仅在此页面上,以及如何解决?

编辑:

我找到了解决方案。我必须添加一个字符。

之前:

    <link rel="stylesheet" href="public/css/style.css">

之后:

    <link rel="stylesheet" href="/public/css/style.css">

0 个答案:

没有答案
相关问题