【问题标题】:Getting error from expressjs while running as transferred with MIME type text/html使用 MIME 类型 text/html 传输时从 expressjs 获取错误
【发布时间】:2015-06-28 09:09:30
【问题描述】:

我将expressjs 作为本地服务器运行。我收到这样的错误..这里有什么问题?

Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:3000/js/lib/bootstrap/dist/css/bootstrap.min.css".
localhost/:11 Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:3000/js/lib/angular/angular.min.js".
localhost/:10 Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:3000/js/lib/jquery/dist/jquery.min.js".
localhost/:12 Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:3000/js/scripts/app.js".

这是我的html:

<!DOCTYPE html>
<html ng-app="myNewApp">
<head>
    <meta charset="utf-8"> //i already declared the content type here.
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>My New App!</title>
    <link rel="stylesheet" href="/js/lib/bootstrap/dist/css/bootstrap.min.css">
</head>
<body>
    <script src="/js/lib/jquery/dist/jquery.min.js"></script>
    <script src="/js/lib/angular/angular.min.js"></script>
    <script src="/js/scripts/app.js"></script>
</body>
</html>

我的server.js:

var express = require("express"),
    app = express();

app

    .use(express.static( __dirname + 'public'));


app

    .get('*', function (req, res) {
        res.sendfile('public/main.html');
    })


app.listen(3000);

【问题讨论】:

  • 为什么是app.get('*',... 而不是app.get('/',...
  • 我猜两者都是一样的。 * 小心点...
  • 我不这么认为。换个试试看

标签: html express content-type


【解决方案1】:

我将所有lib 资产移至public 目录。它有效。

【讨论】:

    猜你喜欢
    • 2018-12-13
    • 1970-01-01
    • 2020-06-15
    • 2020-02-14
    • 1970-01-01
    • 2014-10-16
    • 2011-07-18
    • 2011-12-24
    • 2012-05-20
    相关资源
    最近更新 更多