问题描述
以下代码是一个示例代码,用于在node.js上快速提供静态文件。如果我问服务器一个.css文件没有问题,但是如果我问一个诸如jpg或png的图像,它将加载一个白页(没有/ GET错误或任何东西,一个简单的白页)。在浏览器的开发人员工具中,我看到以下警告:1资源被解释为文档,但以MIME类型image / jpeg传输。我该如何解决?
The following code is an exemple of code to serve static files in express on node.js. If I ask the server a .css file there is no problem, but if I ask an image such as a jpg or png, it loads a white page (no /GET error or anything, a simple white page). In my developer tool in my browser I see the following warning: 1Resource interpreted as Document but transferred with MIME type image/jpeg. How can I fix this?
我正在使用cloud9ide并表示2.4.6
I am using cloud9ide and express 2.4.6
var express = require("express"),
app = express.createServer();
app.use(express.static(__dirname + '/static'));
app.get('/', function(req, res){
res.send('Hello World');
});
app.listen(process.env.C9_PORT);
推荐答案
这似乎是cloud9 ide中的一个错误。我在本地尝试了我的代码,它起作用了。在cloud9ide上有一张票在打开:
It seems to be a bug from cloud9 ide. I tried my code locally and it worked. There is a ticket open on cloud9ide at: http://cloud9ide.lighthouseapp.com/projects/67519/tickets/390-get-png-image-not-working-in-preview-mode#ticket-390-4
这篇关于静态图片文件在node.js / express中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!