저는 Stackoverflow에 익숙하지만 일반적으로 몇 가지 문제가있을 때 일반적으로 여기에 대한 해결책을 찾았지만 이번에는 그렇지 않았습니다.node.js 서버 및 .html 파일
나는 이틀 전에 node.js에서 작업하기 시작했습니다. node.js로 http 서버를 만들었고 몇 달 전에 몇 가지 테스트 목적으로 페이지를 만들었지 만 내 컴퓨터에서 내 페이지를 호스팅하면 작동하지만 jQuery와 같이 html 페이지에 포함 된 javascript 파일이 없어도 작동합니다. 및 일부 그래프 lib.
IE 디버거로 디버깅하려했지만 해결할 수 없습니다.
재미있는 점은 내 디스크에서 동일한 페이지를 열 때 .html
파일을 두 번 클릭하면 오류없이 정상적으로 실행된다는 것입니다.
내 질문은 내가해야 할 일이다. node.js로 뭔가를 놓쳤는가?
나는 페이지에 하나 개의 HTML5 캔버스 요소를 가지고 있고, 어쩌면 그 문제는
이것은 내 index.html을
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello Dialog</title>
<meta content="IE=edge" http-equiv="X-UA-Compatible">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta http-equiv="Cache-Control" content="no-store">
<meta http-equiv="cache-control" content="max-age=0">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT">
<meta http-equiv="pragma" content="no-cache">
<link href="css/ui-lightness/jquery-ui-1.9.2.custom.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="RGraph.line.js"></script>
<script type="text/javascript" src="RGraph.common.core.js"></script>
<script type="text/javascript" src="RGraph.drawing.background.js"></script>
<script type="text/javascript" src="./js/jquery-1.8.3.js"></script>
<script type="text/javascript" src="./js/jquery-ui-1.9.2.custom.min.js"> </script>
<script type="text/javascript" src="index.js"></script>
<script type="text/javascript" src="temperature(1).json"></script>
</head>
<body style="font-size: 10px;">
<button id="btn_hello">Say Hello</button>
<button id="btn_hello1">LUKA</button>
<button id="btn_hello2">ANJA</button>
<button id="btn_hello3">MARKO</button>
<div id="dlg_hello">Hello World!</div>
<canvas id="graph" width="600" height="500"></canvas>
<script>
var data = [];
var limit;
var Temp = [];
var TimeStamp = [];
function readTextFile(file, callback) {
var rawFile = new XMLHttpRequest();
rawFile.overrideMimeType("application/json");
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function() {
if (rawFile.readyState === 4 && rawFile.status == "200") {
callback(rawFile.responseText);
}
}
rawFile.send(null);
}
readTextFile("temperature(1).json", function(text){
data = JSON.parse(text);
for(var i =0; i<Object.keys(data).length; i++)
{
//alert(parseFloat(data[i].TimeStamp));
TimeStamp[i] = data[i].TimeStamp;
Temp[i] = parseFloat(data[i].Value);
}
DrawGraph(Temp, TimeStamp);
});
function DrawGraph(data, timestamp)
{
var line = new RGraph.Line({
id: 'graph',
data: data,
options: {
labels: timestamp,
gutterLeft: 55,
gutterRight: 35,
gutterBottom: 35,
gutterTop: 35,
title: 'A basic line chart',
backgroundGridColor: '#aaa',
backgroundGridDashed: true,
textAccessible: true,
scaleZerostart: true,
labelsOffsety: 5
}
}).draw();
}
</script>
</body>
</html>
이며,이 Node.js를에 server.js입니다
var http = require("http");
var fs = require("fs");
var windows1250 = require("windows-1250");
var ht = fs.readFileSync('./index.html',"utf-8");
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html','Content-Length':ht.length});
res.write(ht);
res.end();
console.log(req.url);
}).listen(8888, function() {console.log("server is listening on port 8888");});
리소스 파일이 서버에 의해 보내지지 않은 것 같습니다. 당신은 오직 다른 파일 (js 스크립트와 CSS)이 아닌 Html 인덱스 만 보내고 있습니다. –
그는 익스프레스에서 외부 js와 css를 사용할 수 있습니다. –