简体   繁体   English

TypeError:无法读取未定义的属性(读取'indexOf')

[英]TypeError: Cannot read properties of undefined (reading 'indexOf')

I keep on getting the TypeError Error when ever I start my application, but only one of the Error's is in my Actual app.js file.每当我启动我的应用程序时,我都会不断收到 TypeError 错误,但我的 Actual app.js 文件中只有一个错误。 The rest are in express's files.其余的都在 express 的文件中。 My code:我的代码:

function checkHttps(req, res, next){
  // protocol check, if http, redirect to https
  
  if(req.get('X-Forwarded-Proto').indexOf("https")!=-1){
    return next()
  } else {
    res.redirect('https://' + req.hostname + req.url);
  }
}

But the rest of the files I have no control over.. How do I fix this?但我无法控制的其余文件..我该如何解决这个问题?

If you want to get the protocol you can go with req.protocol .如果你想获得协议,你可以使用req.protocol

If X-Forwarded-Proto is a header, you need to go with如果X-Forwarded-Proto是标头,则需要使用

req.headers.get('X-Forwarded-Proto').indexOf("https")!=-1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ReactJS/Firebase:TypeError:无法读取未定义的属性(读取“indexOf”) - ReactJS/Firebase: TypeError: Cannot read properties of undefined (reading 'indexOf') 未捕获的类型错误:无法读取未定义的属性(读取“indexOf”) - Uncaught TypeError: Cannot read properties of undefined (reading 'indexOf') Firebase:无法读取未定义的属性(读取“indexOf”) - Firebase: Cannot read properties of undefined (reading 'indexOf') Next.js:无法读取未定义的属性(读取“indexOf”) - Next.js: Cannot read properties of undefined (reading 'indexOf') 类型错误:无法读取未定义的属性(读取“createdTimestamp”) - TypeError: Cannot read properties of undefined (reading 'createdTimestamp') TypeError:无法读取未定义的属性(读取“forEach”) - TypeError: Cannot read properties of undefined (reading 'forEach') TypeError:无法读取未定义的属性(读取“学生”) - TypeError: Cannot read properties of undefined (reading 'students') TypeError:无法读取未定义的属性(读取“addEventListener”) - TypeError: Cannot read properties of undefined (reading 'addEventListener') TypeError:无法读取未定义的属性(读取“国家”) - TypeError: Cannot read properties of undefined (reading 'country') TypeError:无法读取未定义的属性(读取“然后”) - TypeError: Cannot read properties of undefined (reading 'then')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM