nodejs에 문제가 있습니다. 아무도 나를 도와 줄 수 있는지 확인하십시오.url의 매개 변수 전달하기 - nodejs
나는 내가 빈 페이지로 이동하고 보낼 때하는 내가, 내가 그것을 보낼 수 없습니다입니다
page.html?s=1
같은 값으로 PARAM을 전달해야하는 page.html 있습니다.
server.js는 다음과 같습니다
var app = require('http');
var fs = require('fs');
var path = require('path');
var url = require('url') ;
var http = app.createServer(function handler(request, response) {
var filePath = '.' + request.url;
if (filePath == './')
filePath = './index.html';
var extname = path.extname(filePath);
var contentType = 'text/html';
switch (extname) {
case '.js':
contentType = 'text/javascript';
break;
case '.css':
contentType = 'text/css';
break;
case '.json':
contentType = 'application/json';
break;
case '.png':
contentType = 'image/png';
break;
case '.jpg':
contentType = 'image/jpg';
break;
case '.wav':
contentType = 'audio/wav';
break;
case '.xml':
contentType = 'text/xml';
break;
}
fs.readFile(filePath, function (error, content) {
if (error) {
if (error.code == 'ENOENT') {
fs.readFile('./404.html', function (error, content) {
response.writeHead(200, {'Content-Type': contentType});
response.end(content, 'utf-8');
});
}
else {
response.writeHead(500);
response.end('Sorry, check with the site admin for error: ' + error.code + ' ..\n');
response.end();
}
}
else {
response.writeHead(200, {'Content-Type': contentType});
response.end(content, 'utf-8');
}
});
}).listen(3100);
console.log('Server started at 3100');
당신이 더 많은 정보가 필요하면 알려주세요.
그리고 HTTP/200 리턴 코드는 ...인가? 어쩌면 서버의 일부 로그일까요? 누가 "파일명? s = 1"을 쿼리 파트 s = 1과 파일 이름 (나는 node.js 실무자가 아닙니다. 죄송합니다.)로 분할합니까 – Dilettant