req.headers.host
을 Express.js에서 사용하고 Nodejs 6을 SSL 사용 서버에서 사용하는 경우 정의되지 않은 헤더 오류가 발생합니다.요청 헤더가 정의되지 않음 - nodejs SSL
내 코드 :
www-0 TypeError: Cannot read property 'indexOf' of undefined
req.headers.host
을 Express.js에서 사용하고 Nodejs 6을 SSL 사용 서버에서 사용하는 경우 정의되지 않은 헤더 오류가 발생합니다.요청 헤더가 정의되지 않음 - nodejs SSL
내 코드 :
www-0 TypeError: Cannot read property 'indexOf' of undefined
익스프레스의 문서 req.hostname에 대한 섹션이 있습니다 어떤 메신저 점점
if(req.headers.host.indexOf('domain.com')>-1){
......
}
오류가 발생했습니다.
이 같은 일을보십시오 :
if (req.hostname === 'domain.com') {
..........
}
익스프레스의 app.js의 내부 당신이 할 수있는 파일, 나를 위해 일한 :
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!' + ' Hostname is ' + req.hostname);
});
app.listen(3000, function() {
console.log('Example app listening on port 3000!');
});
안녕하세요, 'req.hostname : undefined' 이것은 많은 요청에 대해 무엇을 얻고 있는지입니다. –
더 나은 컨텍스트를 제공하기 위해 내 대답을 업데이트하려고합니다. –
@FahidMohammad 전에 말했듯이'req.hostname' (또는'req.headers.host')이 항상 정의되어서는 안된다. – robertklep
이의 맥락은 무엇을? 당신이 console.log 객체'req.headers'를 보았을 때 당신은 무엇을 보았습니까? –
'console.log'를 할 때'undefined'가됩니다. –
Express에서 수신중인 요청이라고 가정합니다. 'req'는 어떻게 생겼을까요? –