简体   繁体   English

不支持MIME类型('text / html')

[英]MIME type ('text/html') is not a supported

Here are some lines of code... I have another application running that is setup exactly the same and I am having no issues. 这是一些代码行...我正在运行另一个应用程序,该应用程序的设置完全相同,并且没有问题。

app.use('/app', express.static(__dirname + "/public"));

Here is the link tag 这是链接标签

<link rel="stylesheet" type="text/css" href="/app/css/app.css">

It does the same with this img tag 此img标签的功能相同

<img src="/app/img/SCS-NewLogo_donl.svg" height="65px" width="350px" id="sc-logo">

I am not sure why, but it seems to be sending the file as HTML. 我不知道为什么,但是似乎是以HTML格式发送文件。 Usually this means the file is not found on the server, but I checked myself and confirmed that it is. 通常,这意味着在服务器上找不到该文件,但是我检查了一下并确认是该文件。

Full file 完整档案

const express = require('express');
const config = require('./lib/config');
const bodyParser = require('body-parser');
const URLS = require('./lib/URLS.js');

const PORT = process.env.PORT || 9005;
const ENV = config.ENV || 'TEST';
const SERVER = config.SERVER;
const app = express();

app.set('views', './views');
app.set('view engine', 'ejs');

app.use('/app', express.static(__dirname + "/public"));
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

app.all(/^\/apps$/, function (req, res) {
  res.redirect('/apps/job-search');
});

app.get('/apps/job-search', (req, res) => {
  res.render('pages/search');
});

app.post('/apps/job-search/send-input', (req, res) => {

  // Send data to API server which will handle DB query...
  axios.get(URLS.GatherSearchResults)
    .then(resp => {
      console.log(resp.data);
    }).catch(err => {
      console.log(err)
    });
});

app.listen(PORT, () => {
  console.log('App is listening on port ' + PORT + ' on server ' + SERVER + '...');
});

Directory Structure 目录结构

Root
  public
     css
     img
  views
     pages
       search.ejs
     partials
       header.ejs
       footer.ejs
   app.js

I thinkk I see your issue. 我想我看到你的问题。 After declaring the route /app as static, you remap it to '/apps/job-search' several lines later. 在将路由/app声明为静态后,您可以在几行后将其重新映射到'/apps/job-search'

Change the static line to app.use('/', express.static(__dirname + "/public")); 将静态行更改为app.use('/', express.static(__dirname + "/public")); and your links in the HTML file should start wit /css and /img etc. 并且您在HTML文件中的链接应以/css/img等开头。

Verify that by trying to open one of your existing links, and seeing what content you're currently serving (my guess - it'd be whatever is at '/apps/job-search' ). 通过尝试打开您现有的链接之一,并查看您当前正在提供的内容来进行验证(我想,这将是'/apps/job-search' )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NodeJS,MIME 类型 (&#39;text/html&#39;) 不是受支持的样式表 MIME 类型 - NodeJS, MIME type ('text/html') is not a supported stylesheet MIME type MIME 类型 (&#39;text/html&#39;) 不是受支持的样式表 MIME 类型 - MIME type ('text/html') is not a supported stylesheet MIME type 拒绝应用样式,因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型 - Refused to apply style because its MIME type ('text/html') is not a supported stylesheet MIME type 拒绝应用{filename}中的样式,因为它的MIME类型(&#39;text / html&#39;)不是受支持的样式表MIME类型 - Refused to apply style from {filename} because its MIME type ('text/html') is not a supported stylesheet MIME type Django:拒绝从...应用样式,因为它的 MIME 类型(&#39;text/html&#39;)不是受支持的样式表 MIME 类型 - Django: Refused to apply style from ... because its MIME type ('text/html') is not a supported stylesheet MIME type 拒绝应用“ <URL> &#39;,因为它的MIME类型(&#39;text / html&#39;)不是受支持的样式表MIME类型,并且启用了严格的MIME检查 - Refused to apply style from '<URL>' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled 拒绝应用来自“xxx/style.css”的样式,因为它的 MIME 类型(“text/html”)不是受支持的样式表 MIME 类型 - Refused to apply style from 'xxx/style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type 拒绝应用样式,因为它的 MIME 类型('text/html')不是受支持的样式表类型 - Refused to apply style because its MIME type ('text/html') is not a supported stylesheet type MIME 类型 (&#39;text/html&#39;) 错误 - MIME type ('text/html') Error 什么是 MIME 类型('text/html'),为什么 chrome 不支持它以及如何禁用它 - What is MIME type ('text/html'), Why is it not supported on chrome and how can I disable it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM