假设我们首先调用了 app.set('thePath', thePath)
,下面的内容有区别吗?
app.use('/', express.static(thePath))
app.use(express.static(thePath))
app.use(express.static(app.get('thePath')))
似乎 (1) 和 (2) 会做同样的事情。
据我所知,在 Javascript 中,如果你调用一个函数,它会在调用时计算,所以即使 app.get('thePath')
改变或者如果 thePath
更改,所有这些都将保持不变。
如果有不同,请告诉我是什么以及为什么。
最佳答案
http://expressjs.com/en/4x/api.html#app.use
If path is not specified, it defaults to “/”.
所以是的,1 和 2 是一样的。假设 thePath
是一个指向静态 Assets 有效根目录的变量。
关于javascript - app.use ("/", express.static) 和 app.use(express.static) 之间有区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34735358/