简体   繁体   English

文件更改时如何重定向服务器URL?

[英]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.

相关问题 如何将 url 重定向到另一个 url? - how can I redirect a url to another url? 更改下拉列表后,如何重定向到另一个网址 - On change of dropdown how will I redirect to another URL 如何获取网址的重定向网址 - How can I get the redirect urls for a url 如何从嵌入按钮代码更改结帐页面的重定向URL? - How can I change the redirect url of a checkout page from the embed button code? SAPUI5:如何在更改 url 中的 id 后重定向到 NotFound 页面? - SAPUI5: How can I redirect to a NotFound page after change the id in the url? 使用ReactTable时,如何将该URL更改为该代码中的链接? - How can I change this url to a link in that code when using ReactTable? 我如何在服务器响应中设置 cookie 和 json 并重定向到客户端 url/PassportJS NodeJS - How i can set cookie and json in server response and redirect to client url/ PassportJS NodeJS 当我在 url 斜杠中有参数时,如何重定向到特殊页面? - How can I redirect to a special page when I have parameters in url slashes? 服务器上发生更改时,如何更新网页? - How can I update a webpage when a change occurs on the server? 浏览器不支持HTML5视频时,如何重定向到URL? - How can I redirect to a URL when browser dose not support HTML5 videos?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM