简体   繁体   English

app.use(“ /”,express.static)和app.use(express.static)之间有区别吗?

[英]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) ,以下内容之间是否有区别?

  1. app.use('/', express.static(thePath))
  2. app.use(express.static(thePath))
  3. 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.

相关问题 如果app-是子应用程序,则`app.use(express.static`似乎不起作用 - `app.use(express.static` seems to not working if app - is subapplication 如何配置express.js的app.use(express.static(…)`? - How to configure express.js's `app.use(express.static(…)`? 使用 app.use(express.static('public')) 时如何测试 Express 应用程序; - How to test an Express application when using app.use(express.static('public')); 如何关闭app.use(express.static('/ public')); 快递js - How to turn off app.use(express.static('/public')); Express js 我的 javascript 文件没有链接? 我正在使用: app.use(express.static(__dirname + '/public')); - my javascript file not linking? Iam using: app.use(express.static(__dirname + '/public')); 与 app.use(express.static(...)) 相关的 next() 中间件/路由是什么? - What are the next() middlewares/routes relative to app.use(express.static(…))? app.use(express.static("public")) 是否为每个请求调用中间件? - Does app.use(express.static("public")) call the middleware for every request? Express中app.use()的语法 - Syntax of app.use() in Express app.use无法正常使用Express 4 - app.use not working express 4 在一个文件中需要express,在另一个文件中使用express.static - Require express in one file and use express.static in another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM