[英]how i can redirect server url when file change?
Im trying to uses this function but only print a message in console not redirect the actual url of my server when file is changed 我试图使用此功能,但仅在控制台中打印一条消息,而在文件更改时不重定向服务器的实际URL
watcher.add("/home/diegonode/Desktop/ExpressCart-master/routes/2.mk");
watcher.on('change', function (info) {
console.log(info);
router.get('*',function(req,res){
res.redirect('http://www.google.com'+req.url)
})
});
please help me 请帮我
If you want the user who is on your page to get redirected when the file changes on the server then you will not be able to do that using only server-side code. 如果您希望页面上的用户在服务器上的文件更改时被重定向,那么您将不能仅使用服务器端代码来执行此操作。 You need to send a message to the client, using eg WebSocket, Socket.io, long polling etc. and the client needs to react to that message and do the actual redirection (ie navigate to some URL).
您需要使用例如WebSocket,Socket.io,长轮询等向客户端发送一条消息,客户端需要对该消息做出反应并进行实际的重定向(即导航到某个URL)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.