[英]Is there a difference between app.use(“/”, express.static) and app.use(express.static)?
Is there a difference between the following, assuming that we first have called app.set('thePath', thePath)
? 假设我们首先调用了app.set('thePath', thePath)
,以下内容之间是否有区别?
app.use('/', express.static(thePath))
app.use(express.static(thePath))
app.use(express.static(app.get('thePath')))
It seems like (1) and (2) would do the same thing. 似乎(1)和(2)会做同样的事情。
As far as I know, in Javascript, if you call a function it evaluates at that time being called, so even if app.get('thePath')
changes or if thePath
changes, all of them would stay the same. 据我所知,在Javascript中,如果您调用的函数在被调用时会求值,因此即使app.get('thePath')
更改或thePath
更改,所有这些都将保持不变。
If there is a difference, please let me know what and why it is. 如果有区别,请告诉我原因和原因。
http://expressjs.com/en/4x/api.html#app.use http://expressjs.com/en/4x/api.html#app.use
If path is not specified, it defaults to “/”. 如果未指定路径,则默认为“ /”。
So yes, 1 & 2 are the same. 是的,1和2是相同的。 Assuming thePath
is a variable pointing to a valid root directory of static assets. 假设thePath
是一个变量,指向静态资产的有效根目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.