1
我在cloud9 IDE中進行了以下設置。Cloud9:未呈現nodejs服務器映像(HTML)
項目根文件夾
- 的Hello.html - 包含簡單html標籤(+圖像標籤)預覽顯示圖像
- HelloHtml.js - 節點JS文件,讀取HTML文件,並寫入到客戶(迴應)。 。
- Penguins.jpg - 圖像文件在同一個文件夾中。
當我運行服務並在瀏覽器中點擊URL時,HTML會以「Hello World!」呈現。被顯示爲。但圖像沒有被渲染。 img標籤中應該是src =「」屬性。
圖像文件的路徑應該是什麼?謝謝。
HelloHtml.js
var http = require('http');
var fs = require('fs');
http.createServer(function(request, response) {
response.writeHead(200, {
'Content-Type': 'text/html'
});
fs.readFile('./Hello.html', function(err, data){
if(err) throw err;
response.end(data);
});
}).listen(process.env.PORT);
console.log('Hello World HTML Service has started.');
的Hello.html
<html>
<head>
<title>Node JS</title>
</head>
<body>
<h2>Hello world!</h2>
<img src="Penguins.jpg" />
</body>
</html>