简体   繁体   中英

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

 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM