[英]request.url Express and Node
Im a newbie on node.js, I just wanted to know how to extract the requested url in this code 我是node.js的新手,我只是想知道如何在此代码中提取请求的url
app.use(express.static(__dirname+"/public"));
Thank you for your help 谢谢您的帮助
As you can see on the static middleware source , a middleware is basic a function that receives the parameters (request, response, next_function)
. 如您在静态中间件源上所看到的,中间件是一种基本的接收参数(request, response, next_function)
的函数。
So you could create a function that reads the url before it goes to static middleware. 因此,您可以创建一个函数,该函数在进入静态中间件之前先读取url。
var express = require('express');
var app = express();
var staticfn = express.static(__dirname+'/public');
app.use(function (req,res,next) {
console.log(req.url);
var sendStream = staticfn(req,res,next);
console.log(sendStream.path);
});
app.listen(3000)
As you can see on the send package used by the static middleware, the send function returns a object called SendStream
. 在静态中间件使用的send包上可以看到,send函数返回一个名为SendStream
的对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.