[英]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.